Since we already have that library as a dependency of our repository, it
makes sense to use it as a source of country codes instead of keeping a
list of currencies ourselves.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Since we already have that library as a dependency of our repository, it
makes sense to use it as a source of language codes instead of keeping a
list of currencies ourselves.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Since "sokil/php-isocodes" is a dependency of our repository already, it
makes sense to use it as a source of currency codes instead of keeping a
list of currencies ourselves.
By using that library, we can also validate currency codes using
different sets.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Inside the "data/" directory, we have files with lists of subdivisions
that need to be updated. We have to update them manually, or we automate
that task with a script and GitHub actions.
The two options are very time consuming and also not ideal. We don't
want to deal with that problem and, thinking that the user of this
library may want to show the data that we validate, we should create a
whole library to make it more usable.
The "sokil/php-isocodes" is a simple library that, even supports
translations. It's frequently updated and has gone to major performance
updates.
I am not fond of the idea of requiring an external library to install
Validation, as I have seen that gone wrong before [1]. Ideally, that
would be an optional dependency for people who would like to use those
rules, but to make that happen, we need to release a MAJOR version.
[1]: d072b4de6a
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The PSR-7 has two interfaces that allow us to validate them as files.
This commit will allow some rules to validate those interfaces.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Even though using "filter_var()" to validate domains may is error-prone,
Validation should fully support "filter_var()" as long as the
"FilterVar" exists.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
There is some confusion about integer literals (as we type them into
source code) and integer values (the actual value they represent).
When casting the integer 08 (without quotes), PHP triggers an error as
integers starting with 0 should have base 8. However, when casting the
string '08' as an integer PHP returns the integer 8.
This commit will change the behavior of the "IntVal" rule, allowing it
to accept any integer type and any representation of an integer as a
string.
Reviewed-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
Reviewed-by: Wesley Victhor Mendes Santiago <w.v.mendes.s@gmail.com>
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
This commit will revert the update of subdivision codes [1] since the
way we store this data is very different from the merged branch.
[1]: 8b8f7db713
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
To update the list of subdivisions, I decided to use the iso-codes [1]
instead of GeoNames [2] as it seems like that one is more often updated.
This commit will also create a Bash script to update that list in the
future.
[1]: https://salsa.debian.org/iso-codes-team/iso-codes
[2]: http://www.geonames.org/
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
To update the list of countries, I decided to use the iso-codes [1]
instead of GeoNames [2] as it seems like that one is more often updated.
This commit will also create a Bash script to update that list in the
future.
[1]: https://salsa.debian.org/iso-codes-team/iso-codes
[2]: http://www.geonames.org/
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The only Identity Card we have is the Polish one, that said it makes
more sense to have a specific rule that only validates that, rather than
having a "IdentityCard" rule that only accepts one value.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
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>
The changelogs that this commit will change are confusing. From a code
perspective, the rule Date was renamed to DateTime, and OneOf was
renamed to AnyOf, but because we also created a Date and OneOf rule with
different behaviours, it makes more sense to say that their behaviour
changed, rather than saying that they were created in version 2.0.0.
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>
This documentation is in the "rules" directory, but it should be outside
that directory since the "rules" directory is supposed to only have
documentation about rules.
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>
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>
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>
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>
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>