Commit graph

1250 commits

Author SHA1 Message Date
Konstantin c9850f4ec7
Make sure that "Email" only validates strings
There shouldn't be possible to consider a non-string value as a valid
email anyways, but the real problem is that the "RFCValidation" from
"egulias/email-validator" casts the input as a string which makes PHP
trigger an error.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-09 05:28:51 +02:00
Danilo Correa fbbab77b24
Apply contribution guidelines to "Version" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-03 00:04:39 +02:00
Danilo Correa 69a01249da
Apply contribution guidelines to "Fibonacci" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-03 00:04:39 +02:00
Danilo Correa 4200704bdc
Apply contribution guidelines to "File" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-03 00:04:39 +02:00
Danilo Correa 23656c9030
Apply contribution guidelines to "Finite" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-03 00:04:39 +02:00
Danilo Correa 0be63bd313
Apply contribution guidelines to "FalseVal" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-03 00:04:38 +02:00
Danilo Correa eb232247da
Apply contribution guidelines to "Factor" rule 2018-10-03 00:04:38 +02:00
Moritz 03ea1b75f6
Create "Isbn" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-10-02 17:32:08 +02:00
Danilo Correa 4106589e7f
Apply contribution guidelines to "Extension" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-24 21:28:20 +02:00
Danilo Correa 1b4a904871
Apply contribution guidelines to "Luhn" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-24 21:23:17 +02:00
Henrique Moody 478e248dad
Remove unnecessary inheritance from "Yes" rule
The "Yes" rule extends "Regex" rule. The only reasons why that is useful
is because "Yes" uses regular expressions to validate the inputs.

However, the "Yes" rule is way more complex simply validating a regular
expressing and having "Regex" as its parent is also a little bit
misleading.

This commit will:

* Remove unnecessary inheritance from "Yes" rule;

* Improve the documentation of the "Yes" rule;

* Enhance the unit tests of the "Yes" rule.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-16 19:40:48 +02:00
Henrique Moody ea683e691d
Remove "AbstractRegexRule" class
The "AbstractRegexRule" seems like an unnecessary overhead on top of the
"AbstractFilterRule". In fact, the "Phone" and "Uuid" rule should not
even be children of "AbstractFilterRule".

This commit will remove the "AbstractRegexRule" and replace it with
"AbstractFilterRule" on the rules that are depending on it. As for the
rules that don't depend on it it will replace by "AbstractRule" like
most of the other rules.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-16 18:32:39 +02:00
Danilo Correa 907e24fb8f
Apply contribution guidelines to "MacAddress" rule
This commit will also replace the usage of "mac" to "MAC" since it is an
acronym.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-16 18:26:51 +02:00
Danilo Correa e2e9197f29
Apply contribution guidelines to "Mimetype" rule
This commit will also replace the usage of "mime" to "MIME" since it is
an acronym.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-16 18:15:57 +02:00
Cameron Hall fd13b03d18
Apply contribution guidelines to "Yes" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-16 17:25:26 +02:00
Henrique Moody 35f3dd63af
Remove "AbstractCtypeRule" class
The "AbstractCtypeRule" class is an abstraction that is purely an
overhead on top of the "AbstractFilterRule". Not having a real reason to
exist I thought would be better to just remove it and replace its usage
by "AbstractFilterRule".

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-14 09:08:56 +02:00
Danilo Correa aedf261958
Apply contribution guidelines to "Readable" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-14 08:58:39 +02:00
Danilo Correa 083ccec068
Apply contribution guidelines to "LeapYear" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-14 08:41:14 +02:00
Danilo Correa 5b6184d4e2
Apply contribution guidelines to "NotOptional" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-14 08:40:32 +02:00
Henrique Moody 9283c8ecd9
Do not accept whitespace by default in "Digit" rule
The "Digit" rule is meant to validate digits. However, by default, it
also considers any whitespace character (spaces, new lines, tabs, etc)
as valid.

Since the rule also accepts a list of characters to ignore during the
validation it seemed logical to me to leave the responsibility of
allowing whitespace characters on the hands of the one who uses the
rule.

The messages of the exception are not really consistent, this commit
will also fix that.

It's also clear that the "AbstractCtypeRule" is an unnecessary overhead
since it is only a proxy for "AbstractFilterRule". That one can and
should even be removed after this commit is applied especially because
this commit will also remove the method "filterWhiteSpaceOption" which
is the only substantial difference between "AbstractCtypeRule" and
"AbstractFilterRule".

This commit will also apply our guidelines to the "Digit" rule since we
want to do that to all the rules we have.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-12 10:00:17 +02:00
Henrique Moody 27bd5d204d
Do not accept whitespace by default in "Alpha" rule
The intent of the "Alpha" rule is to validate alphabetic values.
However, it also considers any whitespace character (by default). That
causes some confusion, and unless you check its code or tests, you would
never expect that behavior.

Because of that confusion, I decided to make "Alpha" to not consider
whitespace characters as valid, and since in the constructor of this
rule it's possible to add extra characters to the validation it makes
sense to let the user decide whether they want whitespaces, tabs, new
lines, etc. or not.

This rule, as the same as "Alnum" previously, extends
"AbstractCtypeRule" pretty much to only make it easier to consider any
whitespaces as valid, therefore I saw no reason to keep extending it.
Now "Alpha" extends the "AbstractFilterRule" which is the parent of
"AbstractCtypeRule".

I also took the opportunity to apply our contribution guidelines to
"Alpha" since we want to apply that to all the rules.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-11 11:38:15 +02:00
Henrique Moody 3601adf6db
Create "FilteredValidationException" class
All the classes that were extending "AbstractFilterRule" were throwing
exceptions that were extending "AlphaException". That can cause some
issues when the user has a validation chain with "Alpha" and another
child of "AbstractFilterRule" and expects "AlphaException" specifically.

This commit creates "FilteredValidationException" that can be used as
the parent of the exceptions thrown by rules that extend the class
"AbstractFilterRule".

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-11 11:02:17 +02:00
Danilo Correa 24040c9473 Apply contribution guidelines to "NotBlank" rule 2018-09-10 21:00:53 -03:00
Danilo Correa 0e67549dd9
Apply contribution guidelines to "Pesel" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-10 14:51:52 +02:00
Danilo Benevides 2bb6f66251
Apply contribution guidelines to "LeapDate" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-10 14:51:52 +02:00
Danilo Correa 73a0107349
Apply contribution guidelines to "PhpLabel" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-10 08:18:15 +02:00
Danilo Correa 30993fc4a0
Apply contribution guidelines to "Pis" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-10 08:16:25 +02:00
Danilo Correa e832a99d4c
Apply contribution guidelines to "StringVal" rule
Also creates a "ToStringStub" class to help on testing objects that can
be converted to string.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-06 08:41:12 +02:00
Danilo Correa c7fbded457
Apply contribution guidelines to "NumericVal" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-06 08:41:11 +02:00
Danilo Correa 17f8c50f54
Apply contribution guidelines to "Length" rule
Because of the type hinting some validation could be removed from the
"length" constructor.

While applying the contribution guidelines we could also see some
duplicated logic in the "extractLength" method and that the rule was
validating

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-06 08:41:11 +02:00
Henrique Moody 779c0c1503
Do not accept whitespace by default in "Alnum" rule
The "Alnum" rule is supposed to validate alphanumeric values, but
instead, it also validates any whitespace character as valid.

The rule also accepts a list of characters on its constructor, so it the
users intentionally want some specific characters to also be allowed it
is better than they also defined these characters on the rule's
constructor.

While refactoring the rule I could notice that "AbstractCtypeRule" is
just an overhead that does not add much to it, so instead of extending
it "Alnum" now extends "AbstractFilterRule" directly (which is the
parent of "AbstractCtypeRule").

And since we want all rules to follow our contribution guidelines, this
commit also make sure the "Alnum" rule is in accordance with that.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-04 00:05:24 +02:00
Danilo Benevides 9a8cac06d7 Apply contribution guidelines to "Json" rule 2018-08-30 23:08:27 -03:00
Henrique Moody 5a067faec7
Update "PostalCode" list
Updated the whole list according to the last version found on
geonames.org.

The script that I executed to generate the list is:

curl -L http://download.geonames.org/export/dump/countryInfo.txt |
  sed 's,\t,\;,g' |
  sort -u |
  cut -d ';' -f 1,15 |
  sed -E "/^#/d; /^[A-Z]{2}\;$/d; s,([A-Z]{2})\;(.+),'\1' => '/\2/'\,,g"

After generating the list I few changes had to be made since some of the
postal codes in the list were manually updated because they were not
correct.

This change was made because James Macon reported that "110231" was
not recognized as a valid Colombian postal code.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-29 22:30:50 +02:00
Henrique Moody a039d6d4b9
Fix wrong behavior of "Date" rule
The validation was considering "99" as a valid month and neither
date_parse_from_format() [1] or DateTime::createFromFormat() [2] would
complain about that.

The solution for that was to use checkdate() [3] to verify whether the
date is valid or not. Also, an extra step was added to the validation
that a date that only contains a day would return false since a day
without a month and year is impossible to validate.

Apparently, there is no problem while validation when it comes to time,
therefore nothing needed to be added for this validation.

[1]: http://php.net/date_parse_from_format
[2]: http://php.net/datetime.createFromFormat
[3]: http://php.net/checkdate

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-29 21:46:53 +02:00
Henrique Moody 258a456eec
Setup PHPStan (PHP Static Analysis Tool)
Require "phpstan/phpstan" for development and add to the Travis CI
configuration file to execute the analysis when Travis executes the
build with the version 7.2 of PHP.

The level of the configuration is very week for now (just "1") and still
quite some changes had to be made in order to make the analysis pass. I
hope it does not take much time to increase the level of the strictness
of the analyses.

I tried to configure that before but because of dependencies with
"symfony/validator" it was not possible.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-22 19:10:20 +02:00
Henrique Moody f5c167c411
Merge branch '1.1' 2018-08-22 19:09:55 +02:00
Henrique Moody 1da164a26e
Change how "Sf" rule works
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>
2018-08-22 17:46:21 +02:00
Henrique Moody fe7fed3461
Remove support "egulias/email-validator" ~1.0
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>
2018-08-22 17:22:46 +02:00
Henrique Moody d64d26c681
Intercept throwables in the "Call" rule
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>
2018-08-22 17:04:20 +02:00
Henrique Moody 2fac861aa1
Do not trigger PHP errors in the "Call" rule
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>
2018-08-21 01:22:38 +02:00
Danilo Benevides 2b8acfd790 Apply contribution guidelines to "In" rule 2018-08-19 16:01:10 -03:00
Henrique Moody add542ea48
Update "Tld" rule with IANA's list
This commit will update the list of Top-Level Domains in the "Tld" rule
with the latest version found in the website of IANA (Internet Assigned
Numbers Authority).

The list was created with the commands below:

curl -L curl -L https://data.iana.org/TLD/tlds-alpha-by-domain.txt |
    grep -v '^#' |
    tr '[A-Z]' '[a-z]' |
    sed -E "s,^,',; s/$/', /" |
    tr -d '\n' |
    fold -w 72 -s

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-18 15:10:37 +02:00
Danilo Benevides d022a71f54
Apply contribution guidelines to "Instance" rule
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>
2018-08-16 21:54:17 +02:00
Ismael Elias fad0005fa0
Apply contribution guidelines to "Number" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-16 21:54:17 +02:00
Danilo Benevides 94d2e87b2a
Apply contribution guidelines to "Infinite" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-16 21:54:16 +02:00
Danilo Benevides f01972e208
Apply contribution guidelines to "Imei" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-16 21:54:16 +02:00
Henrique Moody afab4eb2b4
Rename "Related" to "Child"
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>
2018-08-02 11:18:33 +02:00
Henrique Moody a1bc0cd6b4
Apply contribution guidelines to "NestedValidationException"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-02 11:11:04 +02:00
Henrique Moody 3ad35ed545
Remove unneessary information from iterator
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>
2018-08-02 11:09:30 +02:00
Henrique Moody da10941ddc
Apply contribution guidelines to "Validator" class
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>
2018-08-02 10:37:38 +02:00
Henrique Moody 3554288c60
Remove "buildRule" method from "Validator"
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>
2018-08-02 10:37:10 +02:00
Henrique Moody e4483b74f2
Remove unnecessary validation from "Factory" class
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>
2018-08-02 10:23:27 +02:00
Henrique Moody eded93b0df
Merge branch '1.1' 2018-08-01 22:08:30 +02:00
Henrique Moody 0cdd8c4546
Fix issues after merging 1.1
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>
2018-08-01 20:46:34 +02:00
Henrique Moody 57509520a4
Merge branch '1.1' 2018-08-01 20:22:37 +02:00
Andrei Drulchenko 19d6ec8939 fix IntVal() leading zero behavior 2018-08-01 16:06:54 +03:00
Henrique Moody 47f21596a5
Fix casting error in AbstractInterval classes
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>
2018-07-28 05:01:58 +02:00
Axel Wargnier 4f3aa90d1f Fix postalCode for Portugal (PT) 2018-07-25 12:33:08 +02:00
Henrique Moody b26ed6bf39
Simplify "AbstractComposite" class
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>
2018-07-24 08:07:18 +02:00
Danilo Benevides 861216c690
Apply contribution guidelines to "Image" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-07-23 21:55:54 +02:00
Danilo Benevides f308e7962e
Apply contribution guidelines to "Multiple" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-07-16 08:15:57 +02:00
Henrique Moody 667ed36b48
Fix grammatical errors in URL exception message
Although the "U" at the first of URL is a vowel, the abbreviation is
pronounced "you-are-ell". Because the letter "Y" is a consonant in this
case, we should use "a" instead of "an".

Link: https://itknowledgeexchange.techtarget.com/writing-for-business/which-is-correct-a-url-or-an-url/

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-07-02 08:22:41 +02:00
Wojciech Frącz 83bb6e3fc9
Fix wrong behavior when using templates
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>
2018-07-02 07:57:21 +02:00
Singwai Chan c5978eb5b0
Create "Subset" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-07-01 15:08:07 +02:00
William Espindola 5f684e246f
Apply contribution guidelines to "EndsWith" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-07-01 14:11:56 +02:00
Sebastian 8fc2484428
Fix postal code for The Netherlands
Postal code for NL allows for a space between the digits and the
letters.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-29 01:10:31 +01:00
Henrique Moody 4fdd2da19e
Fix wrong behavior with nested exceptions
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>
2018-06-29 00:50:27 +01:00
Adam Benson f5ca4a298a
Fix "IntVal" considering boolean values as valid
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>
2018-06-28 22:09:42 +01:00
Danilo Benevides de53a4b4bd
Apply contribution guidelines to "IntVal" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-23 21:43:05 +02:00
Danilo Benevides f486d521cb
Apply contribution guidelines to "PerfectSquare" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-23 21:43:02 +02:00
William Espindola dc3951edf1
Apply contribution guidelines to "Each" rule
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>
2018-06-23 21:40:39 +02:00
Henrique Moody 70eb87bd77
Merge branch '1.1' 2018-06-23 21:37:53 +02:00
Henrique Moody 54d17abcee
Do not consider any float as integer
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>
2018-06-23 21:15:38 +02:00
Henrique Moody 0e73bc732e
Avoid using unset keys in IpException
The "IpException" was triggering an error when the parameters
"networkRange" or "min" were not defined.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-23 21:00:04 +02:00
Henrique Moody 2ab1f11c99
Create "Equivalent" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-23 17:38:53 +02:00
William Espindola 515b23e02f
Apply contribution guidelines to "Exists" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-20 22:34:21 +02:00
William Espindola 01d6e40da4
Apply contribution guidelines to "Executable" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-20 22:34:21 +02:00
paul karikari c44faf0d3f
Apply contribution guidelines to "Uploaded" rule
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>
2018-06-20 22:34:21 +02:00
William Espindola 0413afc226
Apply contribution guidelines to "Directory" rule
Also consider PHP's "Directory" class as a valid directory.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-20 22:34:21 +02:00
paul karikari 97e94cafcc
Apply contribution guidelines to "Unique" rule
Signed-off-by: Paul Karikari <paulkarikari1@gmail.com>
2018-06-18 23:15:19 +02:00
William Espindola a463f8ab2d
Apply contribution guidelines to "CurrencyCode" rule
Also makes the rule case-sensitive since that is how ISO 4217
shows the currency codes.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-18 20:55:43 +02:00
Emmerson Siqueira 6124176c89
Add support to Countable type for ComparisonHelper
Signed-off-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
2018-06-18 11:13:16 +02:00
paul karikari 5a326b6c97
Apply contribution guidelines to "Type" rule
Also add integration test for Type rule.

Signed-off-by: Paul Karikari <paulkarikari1@gmail.com>
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-15 22:12:17 +02:00
paul karikari 8aa6426ab1
Apply contribution guidelines to "TrueVal" rule
Also add integration test for TrueVal rule.

Signed-off-by: Paul Karikari <paulkarikari1@gmail.com>
2018-06-15 22:12:17 +02:00
paul karikari 8573d5f064
Apply contribution guidelines to "Tld"
Also check if input is scalar before validation.

Signed-off-by: Paul Karikari <paulkarikari1@gmail.com>
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-15 22:12:17 +02:00
William Espindola 8bd7428fe1
Apply contribution guidelines to "CreditCard" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-15 22:12:17 +02:00
William Espindola a79e702173
Apply contribution guidelines to "CountryCode" rule
The "AbstractSearcher" already does most of the job that "CountryCode"
was doing, so using it as parent class made more sense. That also makes
the validation case-sensitive which is not a problem since the standard
ISO 3166-1 in fact enforces an specific case for the country codes.

The documentation about the rule is also updated.

Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-15 18:49:52 +02:00
William Espindola 527553ce99
Apply contribution guidelines to "Cnpj" rule 2018-06-15 17:24:19 +02:00
William Espindola b507d928c1
Apply contribution guidelines to "Cnh" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-11 22:24:28 +02:00
William Espindola 8272f43207
Apply contribution guidelines to "Charset" rule
Also change the constructor of the rule to accept charsets as arguments
instead of being either an array or a string.

Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-11 22:24:28 +02:00
William Espindola 9b4c4ddb4b
Apply contribution guidelines to "Callback" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-11 18:47:28 +02:00
Henrique Moody 1255532501
Apply contribution guidelines to "FilterVar" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-11 18:40:05 +02:00
Henrique Moody 8c41838abe
Apply contribution guidelines to "Url" rule
Also fix a type in the exception message of the "Url" rule.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-11 18:22:09 +02:00
William Espindola 99466513b2
Apply contribution guidelines to "Bsn" rule 2018-06-10 13:01:10 -03:00
William Espindola 68b3f207f8
Apply contribution guidelines to "BoolVal" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-09 08:54:42 +02:00
William Espindola 0010ffffb5
Apply contribution guidelines to "Base64" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-09 08:54:39 +02:00
William Espindola f817655a82
Apply contribution guidelines to "Base" rule
Also create a default template for the BaseException.

Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-09 08:54:34 +02:00
Ismael Elias 6e26ba8837
Apply contribution guidelines to "PrimeNumber" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-09 08:54:30 +02:00
Danilo Benevides 1e89dc26ea
Apply contribution guidelines to "NoWhitespace" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-09 08:54:25 +02:00
paul karikari 1bde3a8e49
Apply contribution guidelines to "Email" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
Signed-of-by: Paul Karikari <paulkarikari1@gmail.com>
2018-06-09 08:54:18 +02:00
Radoslaw Wesolowski 700e23777f
Added .studio tld
https://icannwiki.org/.studio
2018-06-06 14:57:39 +02:00
Danilo Benevides 5fc04558d6
Apply contribution guidelines to "Odd" rule
Also does not allow validation of non-numeric values.

Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-06 08:00:58 +02:00
Ismael Elias c2f6876e4f
Apply contribution guidelines to "Negative" rule
Also does not allow validation of non-numeric values.

Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-06 08:00:58 +02:00
Ismael Elias 72933a718f
Apply contribution guidelines to "Positive" rule
Also does not allow validation of non-numeric values.

Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-05 22:26:58 +02:00
Danilo Benevides c422dc39e4
Apply contribution guidelines to "FloatVal" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-05 09:24:07 +02:00
Danilo Benevides b29bdbd111
Apply contribution guidelines to "Lowercase" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-05 09:22:18 +02:00
William Espindola 36be04c520
Apply contribution guidelines to "AlwaysInvalid" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-04 09:12:14 +02:00
William Espindola 49131c87a7
Apply contribution guidelines to "AlwaysValid" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-04 09:12:11 +02:00
William Espindola b6e3fc6ac0
Apply contribution guidelines to "Cpf" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-04 09:12:07 +02:00
William Espindola 8f47cc37d6
Apply contribution guidelines to "Countable" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-04 09:12:04 +02:00
William Espindola 4976fbaf48
Apply contribution guidelines to "Contains" rule
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-04 09:11:58 +02:00
Danilo Benevides d1932b2e7f
Apply contribution guidelines to "Uppercase" rule
Also make sure that "Uppercase" only accepts strings.

Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-06-02 16:03:11 +02:00
Henrique Moody df9ae14100
Apply contribution guidelines to "IterableType" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-01 14:23:41 +02:00
Henrique Moody 2dc8e72844
Add type hinting and return type to "setTemplate"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-01 10:46:51 +02:00
Henrique Moody 0e52f94c34
Add return type to "reportError()"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-06-01 10:34:21 +02:00
Emmerson Siqueira fa222e04c4
Remove dead code "AbstractInterval"
Signed-off-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
2018-05-31 22:55:34 +02:00
Henrique Moody 24c2ba8faa
Make "Min" always inclusive
Since the rule "GreaterThan" was created, there is no reason to allow
"Min" to not be inclusive.

Also apply contribution guidelines to the rule.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-31 17:14:23 +02:00
Emmerson Siqueira 9eb159f3d9
Rename "MaximumAge" and "MinimumAge" rules
Those rules were renamed to keep consistent with other rules such as
'Max' and 'Min'.

Signed-off-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
2018-05-31 17:01:15 +02:00
Emmerson Siqueira 271ddd1fe0
Rename 'Prnt' rule to 'Printable'
This changes the rule name in order to be more descriptive and explicit
(avoid abbreviation). It also applies the new contribution guidelines.

Signed-off-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
2018-05-31 16:00:43 +02:00
Henrique Moody 6351f7a092
Make "Max" always inclusive
Since the rule "LessThan" was created, there is no reason to allow "Max"
to not be inclusive.

Also apply contribution guidelines to the rule.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-31 15:51:57 +02:00
Henrique Moody da6abf4bdd
Make "Between" always inclusive
Generally speaking it makes more sense to have it always inclusive. Even
though the word "between" does not imply that it is inclusive or
exclusive it's more natural this way.

Besides, users can always use "GreaterThan" and "LessThan" rules in case
that is necessary.

Removing this boolean parameter reduces a bit of the complexity of the
rule.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-31 15:10:59 +02:00
Henrique Moody 9b20d6dae2
Create "GreaterThan" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-31 14:47:22 +02:00
Henrique Moody 9d0d750a18
Create "LessThan" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-31 14:01:45 +02:00
Emmerson Siqueira 0a031649a8
Apply contribution guidelines to "Attribute" rule
Signed-off-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
2018-05-31 13:50:36 +02:00
paul karikari 51ec5e1b95
Apply contribution guidelines to "Even" rule
Also add an extra validation to the rule, not allowing non-integers to
be considered as even numbers.

Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
2018-05-31 08:37:38 +02:00
Henrique Moody 3d2136e2ad
Remove unused exception classes
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-28 18:31:36 +02:00
Henrique Moody 71ecea32e6
Make getMessages() return the names or ids as keys
This method change the behavior of "getMessages()" by changin the keys
of its return to the "id" of the specific exception that was triggered.

It also allows users to overwrite the templates by passing an array to
it.

This is being requested by many users for a long time. It took that long
because I was thinking too much about how to improve the old method
called "findMesssage()" that I didn't realize that it could be done in a
easier way with the "getMessages()".

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-28 08:38:30 +02:00
Henrique Moody 8c529c433e
Refactor ValidationException
Make the ValidationException a little bit less mutable than before. All
its dependencies are now passed into the constructor.

This commit also make the Factory pass the translator to the exceptions
allowing to define the translator before the exception gets created.
This change is not the ideal one, later I would like to not need the
Singleton from the Factory to do that, but for now it seems like a good
approach.

One more thing that this commit does is to introduce the "id" for
Exceptions. Key can be either the defined "name" or the name of the rule
that throwed the exception. This method will be handy to identify
exceptions better.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-27 16:12:05 +02:00
Henrique Moody d7ebb8c1a7
Remove "Interface" suffix from exceptions
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-27 16:12:05 +02:00
Henrique Moody 167c97bb83
Ensure names are always string
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-27 16:12:05 +02:00
Henrique Moody 64ec329663
Remove findMessages() from NestedValidationException 2018-05-27 16:12:05 +02:00
Henrique Moody 9c81498395
Do not overwrite method configure()
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-27 16:12:05 +02:00
Henrique Moody d85668c359
Convert message keys to string
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-27 16:12:05 +02:00
Henrique Moody 5d0ecabfdc
Declare visibility for constants
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-27 16:12:05 +02:00
Henrique Moody aa4b111c90
Fix wrong templates
The "MinimumAge" exception should use the "{{ name }}" placeholder
instead of the "{{ input }}" once that one can be either the input or a
user-defined name.

In the default message, the placeholder was using sprintf format, but
the correct way is to use "{{name}}". Also use the same style of the
other messages in the default message.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-27 16:12:05 +02:00
Henrique Moody 0e81792ec8
Remove method stringify from ValidationException
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-27 16:12:05 +02:00
Henrique Moody e203f8aec5
Apply contribution guidelines to "ObjectType" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-19 19:12:59 +02:00
Henrique Moody 34d42a0d70
Apply contribution guidelines to "CallableType" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-19 17:07:59 +02:00
Henrique Moody 47eaea6f28
Merge branch '1.1' 2018-05-19 16:46:58 +02:00
Tim Bond 020ea1ebb5
Update type parameters for Validator doc blocks
The "@param" tag uses phpdoc types. However the "@method" tag uses PHP's
type declarations. Therefore, "mixed" refers to a class whose literal
name is mixed and not the "mixed" keyword. Since "mixed" is not a valid
class name in this context, the type paramaters should be removed.

Additionally, the "callable" type paramater can be used on the
"callback" validation method.

References:
[1]: http://docs.phpdoc.org/references/phpdoc/tags/param.html
[2]: http://docs.phpdoc.org/references/phpdoc/types.html
[3]: http://docs.phpdoc.org/references/phpdoc/tags/method.html
[4]: http://php.net/functions.arguments#functions.arguments.type-declaration
[5]: http://docs.phpdoc.org/references/phpdoc/types.html
Reviewed-by: Henrique Moody <henriquemoody@gmail.com>
2018-05-19 16:26:44 +02:00
Tim Bond 4c996258a1
Update NestedValidationException doc block 2018-05-19 16:19:16 +02:00
MacFJA df985765a6
Update French subdivision codes 2018-05-19 16:18:28 +02:00
Bram Van der Sype 7b5a2928ff Apply contribution guidelines to "NotEmpty" rule 2018-05-02 16:04:05 +02:00
Emmerson Siqueira 2bcc164b35
Apply contribution guidelines to "ArrayVal" rule
Signed-off-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
2018-04-02 23:19:22 +02:00
Henrique Moody bfdea5b5bd
Apply contribution guidelines to "ResourceType" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-03-27 00:44:48 +02:00
Henrique Moody ad9cab5daf
Apply contribution guidelines to "NullType" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-03-27 00:32:05 +02:00
Henrique Moody 435187298a
Apply contribution guidelines to "IntType" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-03-27 00:25:26 +02:00
Henrique Moody ec8cb734b3
Apply contribution guidelines to "FloatType" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-03-27 00:17:34 +02:00
Henrique Moody 8465180062
Apply contribution guidelines to "BoolType" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-03-27 00:09:58 +02:00
Henrique Moody 10ce811f0e Make "Between" rule extend "AbstractEnvelop"
The "Between" rule is composed by two rules: "Min" and "Max". However it
has its specific exception and message. This commit makes it extend the
"AbstractEnvelop" class.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-03-22 19:47:57 +01:00
Henrique Moody e879c62f60 Create "AbstractEnvelope" class
This abstract class is very similar to "AbstractWrapper" the difference
is that "AbstractWapper" will throw the exceptions of the rule that is
defined inside it, while "AbstractEnvelope" uses the exception of the
rule that extends it.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-03-22 19:41:10 +01:00
Henrique Moody 04b3c78ba7 Use ValidationException when no exception is found
Before this change every create rule must have an exception. This commit
allows to create rules without specific exceptions, so when the
exception of the rule is not found Validation uses ValidationException
instead.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-03-22 19:28:53 +01:00
Emmerson Siqueira ad61c49eca Apply contribution guidelines to "ArrayType" rule 2018-03-16 11:19:14 +01:00
Henrique Moody 2069e706b8
Apply contribution guidelines to "StringType" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Co-authored-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
2018-03-09 15:56:10 +01:00
Henrique Moody 848c57d5ed
Apply contribution guidelines to "ScalarVal" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Co-authored-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
2018-03-09 15:07:58 +01:00
Henrique Moody b696070874
Refactor "KeySet" rule
Do not extend AllOf exception, but instead extend "AbstractWrapper".
2018-03-03 18:59:36 +01:00
Henrique Moody 60e3fc3740
Refactor "Between" rule
The "Between" rule was extending the "AllOf" rule and adding "Max" and
"Min" rules to the chain. Because of that, when the rule failed we could
get the "MinException" or the "MaxException" exception, and only if both
failed that we would get the "BetweenException".

With this change it will always get the "BetweenException" which makes
it more explicit.

Also, the "Between" is not using the same standard required in the
Contribution Guidelines.
2018-03-03 18:06:26 +01:00
Henrique Moody 8d44bc3407
Refactor rules related to age
The "Age" rule was removed because it had too many responsibilities.
Instead "MaximumAge" was created (since there is already "MinimumAge").

This commit also introduces "AbstractAge" rule that is been used in both
mentioned rules.
2018-02-24 09:28:54 +01:00
Jens Segers 51ce465b8c
Create "Nullable" rule 2018-02-23 09:20:51 +01:00
Henrique Moody 92a8ab13cf
Fix coding standards
These are the changes after running the last version of PHP-CS-Fixer.
2018-02-04 01:00:30 +01:00
Henrique Moody fb2ebaf5d6
Apply contribution guidelines to "DateTime" rule
This commit also makes some changes in how the `DateTime` rule behaves,
by not accepting `DateTimeInterface` as valid when a format is given.

Also:
- Create `DateTimeHelper` to eliminate some code duplication;
- Create integration tests for `DateTime` rule;
- Rename "format" placeholder to "sample" in the message;
- Update documentation of "DateTime" rule.
2018-01-30 20:17:10 +01:00
Henrique Moody 2007c7dc6e
Create "Time" rule 2018-01-30 09:47:41 +01:00
Henrique Moody 0db1cd6e1b
Create "Date" rule 2018-01-29 09:39:57 +01:00
Henrique Moody c80524b457
Method assert() should not have a return value
One this method should throw an exception when the input is not valid,
returning `TRUE` when it succeeds is not really consistent.
2018-01-28 17:38:40 +01:00
Henrique Moody 30dc089565
Method check() should not have a return value
One this method should throw an exception when the input is not valid,
returning `TRUE` when it succeeds is not really consistent.
2018-01-28 17:38:40 +01:00
Henrique Moody ccf60f0ee3
Method validate() should always return a boolean 2018-01-28 17:38:36 +01:00
Henrique Moody aa7d84c3ea
Refactor "AbstractWrapper" class
This commit also creates `AbstractLocaleWrapper` to help creating
locale-based rules.
2018-01-28 13:20:27 +01:00
Henrique Moody 550795c1e2
Move namespace "SubdivisionCode" to "Locale" 2018-01-28 13:06:55 +01:00
Henrique Moody 8a09799e7e
Also read private properties of parent classes 2018-01-28 13:06:10 +01:00
Henrique Moody 9bad066765
Apply contribution guidelines to "AbstractSearcher"
Refactor `AbstractSearcher` class and its children. Also most of the
unnecessary logic that was on `AbstractSearcher` was put back into `In`
class.

This commit also updates all "SubdivisionCode" rules.

The script used to create the classes can be found on:
https://gist.github.com/henriquemoody/ec404f994a87b18c7771
2018-01-19 21:41:34 +01:00
Henrique Moody c33bcce239
Create UndefinedHelper trait
In order to remove some code duplication and make this validation
reusable that the trait `UndefinedHelper` is being created.
2018-01-18 21:02:01 +01:00
Henrique Moody 2a2bb6dd76
Apply contribution guidelines to "Identical" rule 2018-01-15 09:35:22 +01:00
Henrique Moody 02b51782c3
Apply contribution guidelines to "Equals" rule 2018-01-15 09:16:45 +01:00
Henrique Moody 1f217dda66
Refactor Factory class
With this code the Factory class will be used also to create Exceptions.

In order to do that, the AbstractRule::reportError() was changed, so the
tests of the AbstractRule class.

What this commit also does:
- Port code to PHP 7;
- Do not keep the default instance of the Factory in the Validator
  class;
- Make Factory final.
2018-01-14 16:26:35 +01:00
Henrique Moody 2d7e2ea48f
Add "respect/stringifier" as dependency
Due to this change it was possible to identify that NotEmptyException,
and NotOptionalException where not working as they should. A fix was
made along with this commit.
2018-01-06 14:07:03 +01:00
Henrique Moody ef975629f3
Changes on PHP-CS-Fixer configuration
Because of `declare(strict_types=1)` some changes were necessary.
2018-01-04 17:59:37 +01:00
Henrique Moody b10206bd28
Merge branch '1.1' 2018-01-02 22:57:58 +01:00
Henrique Moody ee9e69776a
Merge branch '1.0' into 1.1 2018-01-02 22:47:22 +01:00
Henrique Moody c931e2504b
Change conditions for Domain validation
Domains can have `--` as long as they don't start or end with `-` in its
parts.
2018-01-02 22:24:43 +01:00
Henrique Moody 37a71de7d0
Try to find template from default templates first
When executing `ValidationException::setTemplate()` using a template
key, it does not try to select the template, but instead it uses the
template key as the template itself.

In order to fix this behaviour, there is now a check for a key with the
defined template. In case the template was not found, use the defined
template as the template itself.
2018-01-02 21:56:07 +01:00
Henrique Moody 5b7ea399c0
Fix coding standards 2017-11-12 14:21:46 +01:00
Henrique Moody d8e5f305a7
Remove "malkusch/bav" as a dependency
This packages is not maintained anymore, therefore it should be removed
from our codebase.
2017-11-12 13:59:05 +01:00
Henrique Moody 20979898c5
Merge branch '1.1' 2017-10-17 12:38:16 +02:00
Henrique Moody 22f1f14430
Merge branch '1.0' into 1.1 2017-10-17 12:15:51 +02:00
Henrique Moody 14572537fe
Improve "Phone" rule
- Only allow spaces and not "\t" or "\n";
- Once the number has a "(", it needs a ")".
2017-10-17 09:51:09 +02:00
RCooLeR 191ee47fc0
Update regex of "Phone" rule
Now regex also matches +1 (555) 555 5555
2017-10-17 08:58:47 +02:00
mazanax 8b3790103e
Create "Luhn" rule 2017-10-16 20:38:56 +02:00
Henrique Moody fd1964d887
Merge branch '1.1' 2017-10-16 10:43:22 +02:00
Henrique Moody 631affdbf2
Merge branch '1.0' into 1.1 2017-10-16 10:39:15 +02:00
Tim Strijdhorst c013fac277
Fix currency code for Belarusian Ruble
References:
- https://en.wikipedia.org/wiki/ISO_4217
- http://www.xe.com/iso4217.php
2017-10-16 10:16:47 +02:00
Lars Decker a17e5e74bc
Add missing "MinimumAge" parameter 2017-10-15 19:52:26 +02:00
Jens Segers 7d42813fb7
Create "Base64" rule 2017-10-15 19:38:31 +02:00
Dick van der Heiden 327297ca6f
Create "Uuid" rule 2017-10-15 18:34:38 +02:00
Ian d65e713080
Improve grammar of "Equals" rule 2017-10-15 18:27:36 +02:00
Mikhail Vyrtsev 41658279e8 Codestyle fixed according to @nickl- 2017-06-29 16:26:47 +03:00
Mikhail Vyrtsev c50c27eecb Removed unwanted semicolon 2017-06-29 15:49:48 +03:00
Mikhail Vyrtsev 19174a8cb1 Fix codestyle according to @nickl- 2017-06-29 15:36:09 +03:00
Mikhail Vyrtsev 017f78e89e Fix scrutinizer warning 2017-06-29 15:03:50 +03:00
Mikhail Vyrtsev ac3f9c8d78 Removed $cmp variable, creds to @nickl- 2017-06-29 14:40:09 +03:00
Mikhail Vyrtsev 53d4182b18 uhm, well, it was actually fine 2017-06-29 06:37:26 +03:00
Mikhail Vyrtsev 9c89018c22 all that before was wrong >_< >_< 2017-06-29 06:18:40 +03:00
Mikhail Vyrtsev ce3597bce5 fix assertion when neighbour values are equal 2017-06-29 05:54:48 +03:00
Mikhail Vyrtsev 8d8735cdd0 fix indentation >_< 2017-06-29 05:42:29 +03:00
Mikhail Vyrtsev 52c8541b9e New rule: Sorted 2017-06-29 05:18:02 +03:00
Henrique Moody 0338e18e83
Rename rule "Date" to "DateTime"
Also change rules to use `DateTimeInterface` and `DateTimeImmutable`
when possible.
2017-05-01 13:16:59 +02:00
Vitaliy 82f53d27e1
Create "Number" rule 2017-04-19 09:49:58 +02:00
Krzysztof Śmiałek 04e8b72908 Create "Unique" rule 2017-04-12 11:23:44 +02:00
Henrique Moody 4549938e30
Update subdivision codes 2017-04-12 10:54:07 +02:00
Senén b2faf8332b Fix Nif Validator 2017-04-11 23:16:58 +02:00
Henrique Moody 569506bc14
Fix wrong docblock on Validator class 2017-03-27 23:52:34 +02:00
Jonathan Stewmon 298102ba13 Use annotations for variadic methods 2017-03-27 13:37:47 +02:00
Bruno Koga a0ba215524
Create "Pis" rule 2017-03-27 11:42:24 +02:00
Jonathan Stewmon 8851fb5abc
Always display message for AbstractRelated rule
`NestedValidationException` should include all `AbstractRelated` rule
exceptions.

`AbstractRelated` rule failures always indicate an interesting nested
context, which should not be omitted from the final result.

`NonOmissibleExceptionInterface` is a marker interface for
exceptions thrown by instances of `AbstractRelated`, which
facilitates identification of those rules' exceptions with
`instanceof`.
2017-03-27 10:21:45 +02:00
Henrique Moody 2b8c560db4
Merge branch '1.1' 2017-03-14 10:46:47 +01:00
Henrique Moody 5ab87d1dd9
Merge branch '1.0' into 1.1 2017-03-14 10:44:11 +01:00
Henrique Moody dc869ac375
Only return "name" as is if it's a string 2017-03-14 10:28:03 +01:00
Henrique Moody b43c9b103b
Better message for Length rule
Update exception message when minimum value and maximum value are the
same.
2017-02-12 18:18:39 +01:00
Bogus bb5ad2d988
Replaced TLDs with current list from IANA 2017-02-08 09:22:25 +01:00
Henrique Moody 86623fc3ca
SimpleXMLElement can also be used as an array 2017-02-05 15:03:48 +01:00
Bradyn Poulsen d48b55a092
Create "OneOf" rule 2017-02-05 14:49:07 +01:00
Henrique Moody 7ee4ae47d5
Rename "OneOf" to "AnyOf" 2017-02-05 12:28:08 +01:00
Henrique Moody 27d35987be
Create "StringVal" rule 2017-02-04 15:16:00 +01:00
Henrique Moody 25bffa00e2
Merge branch '1.1' 2017-01-26 15:41:19 +01:00
Henrique Moody 03f4abbd08
Merge branch '1.0' into 1.1 2017-01-26 15:39:48 +01:00
Yosmany Garcia 8eb95c2b04
Updated provinces of Cuba
Updated provinces of Cuba according to the change of 2011
2017-01-26 15:38:38 +01:00
Michał Prochowski fa61315079
Czech and slovakia postal code patterns fix. 2017-01-26 15:37:37 +01:00
Renato Moura e4ae02fe94
Fix "Cnpj" rule 2017-01-25 17:41:21 +01:00
Yosmany Garcia 32414451b0
Updated provinces of Cuba
Updated provinces of Cuba according to the change of 2011
2017-01-25 17:36:24 +01:00
Bartłomiej Krukowski c9b78789a7 Invalid doc comment 2017-01-23 12:42:47 +01:00
Andy Snell 94a79c033a
Update MasterCard BIN Range
Updates the CreditCard validator regex for the MasterCard brand to match 16-digit card numbers starting with 22 - 27.  Additionally, updates the unit test for CreditCard with a published test card in the new BIN range.

Additional information on the BIN range update can be found at: https://www.mastercard.us/en-us/issuers/get-support/2-series-bin-expansion.html
2016-12-04 23:56:43 -05:00
Henrique Moody e708edd005
Rename rule "Numeric" to "NumericVal" 2016-11-06 18:45:44 +01:00
Henrique Moody 07a120d058
Upgrade "symfony/validator" version 2016-11-05 14:14:39 +01:00
Henrique Moody 6f5c623926
Use class constant instead of FQCN 2016-10-30 20:16:13 +01:00
Henrique Moody f34a34c0b2
Always use mbstring functions 2016-10-30 10:45:30 +01:00
Henrique Moody 4d72af312f
Update PHP-CS-Fixer settings 2016-10-30 10:39:23 +01:00
Henrique Moody f2bb77bb8e
Create tests for "egulias/email-validator" ~2.1 2016-10-29 15:37:09 +02:00
Henrique Moody c65e1e37f9
Merge branch '1.1' 2016-10-29 15:30:23 +02:00
Henrique Moody 710e807a68
Merge branch '1.0' into 1.1 2016-10-29 15:29:17 +02:00
Henrique Moody f82fcf0762
Prevent "Regex" to process non-string inputs 2016-10-29 15:21:14 +02:00
Henrique Moody bd636cc75e
Add support for "egulias/email-validator" 2.x 2016-10-29 15:20:13 +02:00
Julián Gutiérrez 195a8fe534
Create "Nif" rule
Rule to validate spanish NIF (DNI/NIE/CIF).
2016-10-09 17:50:52 +02:00
Henrique Moody 08ea9b7925
Merge branch '1.1' 2016-09-20 08:45:34 +02:00
Henrique Moody e457f19dbd
Merge branch '1.0' into 1.1 2016-09-20 08:44:39 +02:00
Henrique Moody 98050476c6
Always return a valid exception
If calling the method `getExceptionForPath()` when the exception was
nested but had no child it was returning null. This commit ensures that
it always return a valid exception.
2016-09-19 18:22:39 +02:00
Henrique Moody 6ee9776ea9
Merge branch '1.1' 2016-09-19 11:25:42 +02:00
Henrique Moody 3fa5bc0489
Merge branch '1.0' into 1.1 2016-09-19 11:24:33 +02:00
Emmerson d0a98ae5d3
Date rule accepting scalar and DateTimeInterface 2016-09-19 10:13:01 +02:00
Tomasz Regdos 38aedd01e3
Create "Vatin" rule (VAT identification number)
See https://en.wikipedia.org/wiki/VAT_identification_number
2016-09-19 09:50:50 +02:00
Henrique Moody 332b0d7bb6
Merge branch '1.1' 2016-09-19 09:33:16 +02:00
Henrique Moody c79d8fdf4f
Change file mode of "Image" rule 2016-09-19 09:32:42 +02:00