There are not other VATINs besides the one from Poland. That said, it
makes more sense to have a specific rule that only validates NIP.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit will rename the rule by removing the abbreviation to make it
a bit easier to understand what it does and much easier to find.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Following what is happening with pretty much every class in this
library, this commit will make the public properties of
"AbstractRelated" private.
Because other objects use some of those public properties, this commit
will also implement a couple of methods in "AbstractRelated" so they can
access the values they need.
This commit will also remove the method "decision" that makes dynamic
calls to "assert()," "check()," and "validate()" methods.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The "SubdivisionCode" rule was refactored [1] and now it doesn't need
one rule per country.
This commit will also remove the exceptions that were supposed to be
removed before.
[1]: 718bacad04
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
There are a couple of issues with the "KeyValue" rule:
* When using it with "Not" it does not fetch the exception from the rule
that it creates during the validation.
* It creates a "Validator" rule, which means that it creates two rules
(Validator and the real rule) every time it validates an input.
This commit will fix these two issues and also create integration tests
that will ensure its behavior in case of change.
Co-authored-by: Danilo Correa <danilosilva87@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
There is no much benefit from having individual rules for each country's
subdivision, quite the opposite. It increases the amount of code and
makes it hard to change the implementation of these rules. Right now,
the only sane way to change those rules is with a customized script.
This commit will remove the Subdivision Code rules per country and
instead will put that information into JSON files.
We both wouldn't like to keep this in this library anymore, and we are
considering having another library to deal with this data [1], but since
it seems like it may take some time, looks better to do it temporarily
here.
[1]: https://github.com/sokil/php-isocodes/issues/12
Co-authored-by: Mazen Touati <mazen_touati@hotmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
When using nested "Not" and "AllOf" rules Validation does not fetch the
message of the rule that failed, and instead it fetches the default
message in "AllOfException."
That is because "Not" cannot reach the rules inside "AllOf," making it
impossible to fetch the correct message.
This commit will improve that a bit but making "Not" deal directly with
the rule inside "AllOf" when it has only one rule.
Unfortunately, it will not fix all the issues. For example, when the
negated rule is an "AllOf" with multiple rules and it fails "Not" will
fetch only the first message.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The rule validates any empty string as a valid input, its exception
message states Roman with lower-case "R" and refers to numbers instead
of numerals, which is the most common usage.
This commit will fix both behaviors and also improve the tests for the
rule.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit will also apply the contribution guidelines to the rule and
improve its documentation.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
According to the official documentation [1] the correct way of writing
the "inheritDoc" tag is with the uppercase "D".
[1]: https://docs.phpdoc.org/guides/inheritance.html
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The "Domain" rule duplicates a lot of its logic among the methods
"check()," "validate()," and "assert()." Such duplication makes it hard
to maintain and hard to understand.
Besides that:
- It triggers a PHP error when trying to validate a non-scalar value;
- It does not show the exceptions in the correct hierarchy;
- It allows to change the TLD validation after to object is created.
This commit will fix those issues and create better tests for the rule.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
- Only create objects that are instantiable.
- Validate if validator is a valid Zend Validator after its creation.
- Parse messages from Zend Validator on "assert()" and "check()."
- Upgrade supported version of Zend Validator: version 2.0 has some PHP
deprecations therefore there is no used to support it.
Co-authored-by: Danilo Correa <danilosilva87@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The sorted rule accepts a callback on its constructor that may be used
to filter values from inside the input. However, with the "Call" rule
one can archive almost the same result. Besides that particular
characteristic, its constructor accepts a boolean value to determine
whether the sorting is ascending or descending.
This commit will remove the callback from the constructor and replace
the boolean by a string which can be "ASC" or "DESC."
Along with those changes, this change will make a few more improvements:
- Make the exception message specific about the sorting direction;
- Allow the rule to validate also strings;
- Update documentation.
Co-authored-by: Danilo Correa <danilosilva87@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
After writing the integration tests of the "Vowel" rule we noticed that
it is generating extra double-quotes for the "{{additionalChars}}"
template placeholder.
Besides, it considers any whitespace as valid. That is because in the
past Validation would always consider spaces as a valid.
This commit will also remove the extra double-quotes and do not allow
whitespaces to be considered as valid.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
After writing the integration tests of the "StartsWith" rule we noticed
that it is generating extra parentheses for the "{{startValue}}"
template placeholder.
This commit will also remove those extra parentheses.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
After writing the integration tests of the "Space" rule we noticed that
it is generating extra double-quotes for the "{{additionalChars}}"
template placeholder.
This commit will also remove those extra double-quotes.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
This commit will add a couple of rules that we already use but also
introduce new ones and make sure all the code is in accordance with the
new coding standards.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
After writing the integration tests of the "Punct" rule we noticed that
it is generating extra double-quotes for the "{{additionalChars}}"
template placeholder.
This commit will also remove those extra double-quotes.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
This commit will also remove the second argument from the constructor of
the rule because there is no much use for that, instead if will simply
perform the CountryCode validation.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The new ranges are now 100% accurate by not including any Unicode point
that is not defined into the reference file.
For example, in the old ranges there is this interval:
[\x{3297}-\x{3299}]
That is not accurate because there is no "3298" Unicode point in the
specs. It may be used by another character and it will cause the check
to fail if the user included that particular character.
The new ranges for that previous example are now:
\x{3297}
\x{3299}
And so on...
This commit will make the ranges more accurate with maximum tolerance to
other charcters and also rename the constant name from "GROUPS" to
"RANGES" since they are ranges, not groups.
After writing the integration tests of the "Graph" rule we noticed that
it is generating extra double-quotes for the "{{additionalChars}}"
template placeholder.
This commit will also remove those extra double-quotes.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
After seeing the integration tests of the "Consonant" rule we noticed
that it is generating extra double-quotes for the "{{additionalChars}}"
template placeholder.
This commit will also remove those extra double-quotes.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
After writing the integration tests of the "Cntrl" rule we noticed that
it is generating extra double-quotes for the "{{additionalChars}}"
template placeholder.
This commit will also remove those extra double-quotes.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
The tool we used to verify whether the code base has the correct coding
standard was removed [1].
This commit will set up one that works best for us and will also make
sure we have fully compliant to PS1 and PSR2.
[1]: ffec95acda
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The data in this commit has been gathered, scrapped, organized and
treated based on the Emoji Unicode V11 specification [1].
[1]: https://unicode.org/Public/emoji/11.0/emoji-test.txt
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Because some classes extend the "Regex" class this commit will also
change the implementation of those classes to use "Regex" by composition
instead of extending the class.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
While making sure that Validation uses PHP strict types [1] the compared
value in the "Contains" rule was cast to string. That is problematic
when someone wants to enforce the operation to compare if the input has
a value identical to the expected value.
This commit will fix that by not casting the expected value but also
make sure that string comparison will not be used when it's not a
string.
[1]: ef975629f3
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit will do many different things, but they are all improvements
to the "Ip" rules:
* Remove passing variables by reference: the "Ip" class uses that a lot
to define the start address, end address, and the mask used to
validate a network range;
* Remove double-typed argument from the constructor: the class "Ip"
class has only one argument that can be either a string with the range
of the IP or an integer with options for the "filter_var()" function.
This commit will split it into two different arguments, each of them
used for one of this functionalities;
* Update documentation to show how to validate IPv6.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Because traits are behaviors that are added to a class, it makes sense
to name them with the behavior that they add the classes that use them.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit will make sure that every class, interface, or trait will
have the "@author" annotation in it.
In order to create a list of authors, I used the "git blame" command,
which means that if someone changed or even created the file but does
not have any remaining line will not be shown in the list; it's a
trade-off worth but it is worth it. The other way to do it would be
carefully checking each file.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Some classes and one trait had some mismatch values for their "@author"
annotation and this commit will fix the mismatch putting the correct
authors.
I used the "git blame" command to find out which people changed the file
and created a list based on that information.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The argument "parameters" which is meant to give the wrapped rule's
exception some extra information does not always need to be defined, for
example when the exception does not need any parameter.
The current version of "AbstractEnvelope" required that argument and the
rules that are extending this class are passing an empty array.
This commit will make the "parameters" argument optional. As an extra,
it will make sure the tests from the children of "AbstractEnvelope" are
also covering their parent.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Removes the errant space in the CA PostalCode regex.
This space was introduced by 5a067fa.
It also adds unit tests for the CA PostalCode to validate
the fix.
Reviewed-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
Since the library doesn't need to give support to version 5.4 or less of
PHP using variadics in the constructor of "AbstractFilterRule" seems
better than doing the whole validation.
This commit will also apply the contribution guidelines to
"AbstractFilterRule" and use a better naming for it.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit will allow validation of UUIDs with versions 1, 3, 4 and 5.
Version 2 was not implemented since its adoption is not that broad and
we couldn't find many details about it.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
As it seems, the TLDs "goodhands", "jlc", "panerai", "statoil",
"telecity", and "vista" were removed from the list.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
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>