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>
After the refactoring on the Factory class [1], to throw exceptions of a
specific rule, it is necessary to add the exception namespace of that
rule. That change makes sense when someone wants to create rules from
the Validator class, but when using rules as classes, it's not as handy.
This commit will auto-resolve exception based on the rule namespace,
just as it used to be.
[1]: 1f217dda66
Co-authored-by: Casey McLaughlin <caseyamcl@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Although BCMath is necessary to execute "Ip" and "Iban" rules, we not
required that in the "composer.json" file. That's because if someone
wants to use the library, but doesn't want to use those rules, they
would not need to install that extension.
However, when executing the tests, they will break. This commit will
verify whether the extension exists to test "Ip" and "Iban" rules.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
We already supported PHP 8.0 as our constrains in the "composer.json"
file was ">=7.3", but we were not testing it before.
Because of that, I found a bug on "EndsWith" which is fixed now.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Some amazing features had to be ignored because it conflicts with out
coring standards. I hope to soon fix them so we can use PHPStan to its
fullest potential.
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>
I can't explain why, but depending on the environment, some tests of the
"Call" rule was failing.
This commit will add a test for the "validate()" method, and also use a
more clean way to trigger and handle a PHP error.
Co-authored-by: Casey McLaughlin <caseyamcl@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
According to Wikipedia, also known as the most reliable source of
information on the whole Internet, Serbian postal codes consist of five
digits [1].
Even though it mentions that a six-digit postal code format has been in
place since 1 January 2005 [2], I have not found any Serbian postal code
which consists of six digits.
Maybe someone would prove us wrong, but we will keep the validation as
six-digits from now one.
[1]: https://en.wikipedia.org/wiki/Postal_codes_in_Serbia
[2]: https://web.archive.org/web/20090917083620/http://www.posta.rs/postanskamreza/postanskamreza.asp
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
According to Wikipedia[1]:
> Postal codes in Armenia consist of four digits. Until April 1, 2006,
> they consisted of six digits.
[1]: https://en.wikipedia.org/wiki/Postal_codes_in_Armenia
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
According to Wikipedia[1]:
> A postal code typically consists of an island code, a hyphen
> separator, and a section code.
>
> There are only three island codes: KY1 for Grand Cayman, KY2 for
> Cayman Brac, and KY3 for Little Cayman.
[1]: https://en.wikipedia.org/wiki/Postal_codes_in_the_Cayman_Islands
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
According to Wikipedia [1]:
> Until February 2013, Israel postal codes were 5-digit. Officially the
> 5-digit codes remained valid until 31 January 2013, though they
> continue to be widely used.
This commit changes the "PostalCode" rule to allow either 5 or 7 digits.
[1]: https://en.wikipedia.org/wiki/List_of_postal_codes
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
The intention of the "assert()" method is to show all the errors that a
given input may have. The implementation of the "assert()" method in the
"Each" rule, on the other hand, only reports the first error of each
element of the input.
This commit makes "Each" show all the validation failures of each
element of the input. Also, the implementation of
"AbstractRule::check()" is simply a proxy for the "assert()" method,
and since the "Each" rule extends that class, this commit creates a
custom implementation of the "check()" method.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
The "Call" validator, the "assert()" and "check()" methods, define a
custom error handler so it can handle the validation in case of a PHP
error. However, it does not restor the previous error handler when the
validation fails.
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
We have seen users that want to change the default behavior of parameter
stringifier:
* Change the depth level shown from an array.
* Change the number of elements shown from an array.
* Not add quotes to some parameters.
Because of that, this commit will allow users to customize the parameter
stringifier.
This commit will also update the documentation to instruct how to
customize it.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
There should not be too much code in the ValidationException. It is hard
to test and debug code in exceptions because PHP does not trace further
than their constructor.
This commit will move the message formatting from ValidationException
into a Formatter class (inside a Message namespace).
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The constructor of "Factory" has three arguments and, even though none
of them are needed, they are all required. Those arguments allow users
to customize the namespaces of rules and exceptions, and also to define
a callable that will translate the template messages.
This commit will remove those parameters from the constructor of
"Factory," and create methods that will allow users to customize the
namespaces and the translator.
The methods that this commit will create will not change the state of
"Factory," but they will create a clone with the customizations. It is
imperative that the "Factory" is immutable. Since the "Factory" is a
Singleton, allowing it to change could cause unexpected behaviors.
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>
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>