Instead of creating the Symfony constraints itself "Sf" accepts an
instance of "Symfony\Component\Validator\Constraint".
Creating objects inside a rule, specially from an external library,
makes the rule too complex and also limits the possibilities with the
"Sf" rule since Symfony allows users to create complex validations (even
thought their API is not as simple as ours).
This commit also simplifies the way the messages are passed from Symfony
to the "Sf" when only one constraint has failed; instead of passing
the message of the whole constraint violation list, only the fist
constraint violation message it passed.
The problem that this rule will always have is that when using "Not" to
invert the validation we have a way to get a proper message since
Symfony Validator only return the result of constraints that failed.
That's something the Respect\Validation does in a similar way and to
change it a lot has to be changed.
These changes were checked in "symfony/validator" 4.0 and the version
was added to the "composer.json" file.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The rule "Email" now only supports the version >=2.0 of
"egulias/email-validator". Also a few changes were made to make the rule
a bit simpler.
The method "getEmailValidator()" which was a lazy load of the
"EmailValidator" class was removed in favor of trying to create the
instance of "EmailValidator" in the constructor of "Email". That makes
the rule immutable after its creation.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The callable defined to the "Call" rule may also throw an exception and
as we don't want to have errors nor exceptions that are not part of the
Validation during the validation of inputs it just makes sense to
intercept any instance of Throwable.
This change was initially thought of because in Travis the version 7.4
of PHP was throwing "Error" instead of triggering PHP errors which made
the tests fail.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit make sure that when the callable is executed by the "Call"
rule and PHP triggers an error, the user does not have to deal with it,
and instead the rule will throw "CallException".
Because of the many changes that were made, it didn't make sense to keep
the class "Call" extending the "AbstractRelated" class.
One thing that is a bit problematic with this rule - and with other
rules as well - is that Validation only knows details of a validation
when it fails, because of that we cannot invert the validations that
passed, meaning that the "Not" rule cannot give the proper response to
a validation that passed. This is a know issue that can only be fixed
is we provide a way for Validation do have more granularity control.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Also updates how the tests define the name of the instance by using the
class keyword [1] instead of a string with the class. That is useful
in code analyses be able to identify the usage of these
classes/interfaces.
[1] http://php.net/class#language.oop5.basic.class.class
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
The "NestedValidationException" has exceptions that are its children.
However, we call them "related". This commit updates the term over the
library.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
In the iterator in the "NestedValidationException" the only information
that is necessary is the depth of the message, for that reason all the
other information can (and should) be removed.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Also removes the possibility of the "create()" method to create a new
Validation with predefined rules since that is the behavior that the
constructor already has.
And even though may be a bit scary to make "Validator" final I believe
there should be no reason for this class to be extended, and if there is
it is probably because we are missing something, which I would very much
like to find out.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Because Validator uses a Factory to create rules, it does not make sense
to create rules with this method anymore. Furthermore it goes over the
responsibilities of the "Validator" to create objects.
That said, the existence of such method is only one more point of
maintenance and nothing that brings much values for our uses therefore
it should be remove.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The "ReflectionClass" throws an exception if the class cannot be found,
for that reason the validation with the "class_exists()" function was
unnecessary.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
These two branches are very different, therefore merging is becoming
very hard.
I decided to not put these changes together with 5750952 because it
seems easy to track these changes with a specific commit.
While working on this merge I realized that would make more sense to
create "AbstractComparison" to handle the rules that compare values.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The classes that are children of "AbstractInterval" convert their values
before comparing them.
Because PHP tries to convert values when making comparisons and an
"DateTime" object cannot be converted to integer or float some
validations would result into PHP triggering an error like:
> Object of class DateTime could not be converted to int
> Object of class DateTime could not be converted to float
This commit prevents that to happen by verifying if both compared values
are scalar or not before comparing them with each other.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
There is a log of magic in the "AbstractComposite" that allows an user
to add a rule in multiple ways, remove rules, verify if a rule is
inserted or not. Because of that the class has a lot of complexity and
for unnecessary reasons since we do not use these features internally.
The ideal would be to make this class immutable, however due to many
usages is not possible to do it now, but that is the plan for a near
future - hopefully.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
When a template is set for a chain of rules, does not really matter
which messages the chain can have, the only message to be used should be
the one based on the defined template.
This commit set the same template of a parent rule to its children's
exception. Our first thought was to set the template to its children
however that would mean that if another rule would be added to the chain
we would have to set it as well. Doing that to the children's exception
make sure we only do that once.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Use the same condition to not include child exception into the iterator
to also not show the message of the main exception when using
"getFullMessage()".
The method created to validate that condition should probably be in the
"ValidationException" itself, but this commit is meant to be a bug fix,
which will be released in a PATH version, and creating this public
method would imply that a MINOR version should be released.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The commit 54d17ab tried to fix the that "IntVal" would pass with values
that are not considered as an integer, but it does not change
Even thought the commit 54d17ab fixes part of the wrong behaviour it
left out the filter for boolean values.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Also removed the possibility of validating keys once it's possible to
reach the same behavior by combining this rule with "Call" rule.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Values like "500.00" or 1.0 should not be considered as integer values
even though there is no data loss when they're converted to integer.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The "IpException" was triggering an error when the parameters
"networkRange" or "min" were not defined.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Currently the build is failing because "friendsofphp/php-cs-fixer" does
not support PHP 7.3, but since we do not execute it in PHP 7.3 we can
ignore it for now.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Also introduce "uopz" extension in order to create tests for "Uploaded"
rule.
Signed-off-by: Paul Karikari <paulkarikari1@gmail.com>
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>