[`json_validate` function](https://wiki.php.net/rfc/json_validate)
[added in PHP 8.3](https://php.watch/versions/8.3/json_validate) validates a
given string input to contain valid JSON without decoding it in memory.
This adds a function availability check to `Rules\Json`, and uses the new
function instead of decoding the given input, followed by a last-error check.
The functions from the mbstring can deal find with strings without
forcing an specific encoding. However, sometimes "mb_detect_encoding()"
cannot identify the encoding therefore the functions that expect a valid
encoding will trigger a PHP error.
This commit will remove the unnecessary use of "mb_detect_encoding()."
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
We could simply add version 3.0 instead of replacing it, but I would
like to stimulate people to keep their libraries up-to-date.
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 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>
We have three workflows that automatically update the code. They are
using version 2.0 as a base to create their changes. We need to update
that because the last supported version is 2.1.
Since I do not think it is a good idea to change code every time a new
MINOR version is released, I moved that value to a repository secret.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit will fix an issue but ignore two of them because it will
require some refactoring that won't be possible in a PATCH version.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
One of the reasons for this change is to spare some space on the
Validator class, leaving only real code there. However, the biggest
reason is that IDEs can auto-complete rules after Validator creates the
first rule.
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>
Most Validation errors are sent to Users/Visitors or Clients and as such
might not need to know it was a Key their inputs are being validated
upon.
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>
The third argument of "filter_var" must be either an integer or an
array. On PHP 8 this "FilterVar" rule fails because we always pass that
argument, even if it is null.
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>
This commit will also remove Travis and Scrutinizer and will configure
Codecov as a code coverage tool.
A few changes in the PHPUnit configuration already had to be made
before, but became more visible now. They're along with this commit.
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>
All the rules that extend the "AbstractRelated" class overwrite the name
of the inner-rule even when it already has a name. This leads to some
unexpected behavior, as messages won't show the name of the inner rule
but instead the name of the parent rule.
Co-authored-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>