Commit graph

897 commits

Author SHA1 Message Date
Alexandre Gomes Gaigalas 727e7ccbfa Increase phpstan level from 7 to 8
- Fixed all phpstan errors and ignoreds.
 - False positives now have a "Why:" comment on phpstan config.
2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas 8cafa3f298 Drop PHP 7.4 support 2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas ab3732f91f Use SPDX IDs for licensing
SPDX IDs are shorter than licensing notes previously used, and
adhere better to FOSS standards. It is also machine-readable.
2023-02-19 00:19:10 -03:00
Alexandre Gomes Gaigalas 689026fc7b Improve FilterVar with FILTER_VALIDATE_* options
The `filter_var` function is more of a sanitizer, but we as
a validation library do not care for that use case.

We should treat its sanitizings as a signal for checking if
the type after sanitization matches the option provided.

This fixes #1387
2023-02-19 00:19:09 -03:00
Alexandre Gomes Gaigalas 1481c8e1e5 Updated docheaders 2023-02-13 19:24:37 -03:00
Alexandre Gomes Gaigalas 9ae39de44e Updates for IntVal changes 2023-02-13 19:21:42 -03:00
Alexandre Gomes Gaigalas 74d7f037a4 Merge branch 'omega3000/master' into 2.2 2023-02-13 19:07:48 -03:00
Alexandre Gomes Gaigalas 13f20e7516 Merge branch 'rule/portuguese_nif_rule' into 2.2 2023-02-13 19:02:10 -03:00
Alexandre Gomes Gaigalas e5223a0913 Merge branch 'scruwi/master' into 2.2 2023-02-13 19:00:28 -03:00
Alexandre Gomes Gaigalas 2951dfd342 General fixes for PR#1392 (rupay card validation) 2023-02-13 18:59:09 -03:00
Alexandre Gomes Gaigalas 8e345b798a Merge branch 'rupay-card-validation' into 2.2 2023-02-13 18:53:04 -03:00
Alexandre Gomes Gaigalas 15f148da24 Dusting off. See CHANGELOG.md for more details on this commit 2023-02-13 03:59:11 -03:00
Rakshit 0cd309d9f9
PHPUnit tests for RuPay 2022-10-22 13:47:00 +05:30
toxxxa c7a6f2ebec Fix Decimal rule for float values > 10 2022-06-29 23:01:42 +03:00
Gonçalo Andrade e219da2945 Add rule for validating portuguese fiscal numbers 2022-06-08 14:29:19 +01:00
Markus.Lauer b8ee424082 Allow 5- and 6-digit postal code for Cambodia 2021-08-27 17:13:03 +02:00
Alexander Wühr 660294128f
IntVal: Validate negative numbers properly 2021-05-05 13:34:57 +02:00
Henrique Moody 4c21a7ffc9
Revert "Use "sokil/php-isocodes" on SubdivisionCode"
This reverts commit 9c9c76ebfb.
2021-03-19 15:12:45 +01:00
Henrique Moody 745a5712eb
Revert "Use "sokil/php-isocodes" on CurrencyCode"
This reverts commit f9b9dd21f9.
2021-03-19 15:12:44 +01:00
Henrique Moody f9b9dd21f9
Use "sokil/php-isocodes" on CurrencyCode
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>
2021-02-06 15:52:40 +01:00
Henrique Moody 9c9c76ebfb
Use "sokil/php-isocodes" on SubdivisionCode
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>
2021-02-06 15:09:04 +01:00
Henrique Moody 6c3aed9213
Create "Decimal" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-10-04 14:09:34 +02:00
Henrique Moody 1809e9f4c4
Make "HexRgbColor" rule case-insensitive
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-10-04 12:12:10 +02:00
v0idpwn ff253c78b3
Allow file-related rules to validate PSR-7 interfaces
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>
2020-10-04 12:03:22 +02:00
Olumide Samson 029fa7fe73
Remove "Key" prefix from KeyException message
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>
2020-10-04 11:42:51 +02:00
Henrique Moody 8b2819e9f8
Auto-resolve exception namespaces
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>
2020-10-04 11:26:20 +02:00
Henrique Moody ed304f3406
Check "bcmath" extension before executing tests
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>
2020-10-04 11:21:36 +02:00
Alexandre Gaigalas 2fad28b36b Allow optional space for greek postal codes 2020-08-31 22:54:04 -03:00
Henrique Moody f53b77a186
Add support for PHP 8.0
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>
2020-08-28 08:53:41 +02:00
Henrique Moody 72dd88144e
Update version of "respect/coding-standard"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-08-27 16:21:02 +02:00
Henrique Moody 966c510559
Update version of PHPUnit package
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-08-26 09:47:59 +02:00
Henrique Moody 642602fd43
Update version of PHPStan packages
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>
2020-07-25 22:50:59 +02:00
Cameron Hall fc14c6c669
Do not overwrite pre-defined rule name
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>
2020-07-25 20:34:16 +02:00
Chris Ramakers 44d0af4148
Allow validating domains with "FilterVar" rule
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>
2020-07-21 23:09:18 +02:00
Henrique Moody 3145426472
Update version of "respect/coding-standard"
With that update, we will be fully following PSR-12.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-07-21 22:54:41 +02:00
bmorg 34cbed2c9b
Allow leading zeros when using "IntVal" rule
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>
2020-07-21 21:40:38 +02:00
Henrique Moody 6f3979cb51
Improve unit tests for "Call" rule
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>
2020-07-14 21:47:22 +02:00
Casey McLaughlin f3faf50340
Set timezone to UTC when testing date-related rules
Set default timezone explicitly to UTC so that tests do not fail in
other time-zones.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2020-07-14 21:27:45 +02:00
Daniel Altenburg 0a3f4c6a4b
Update Serbian postal code validation
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>
2020-07-14 21:02:53 +02:00
Henrique Moody 37746f3a6d
Update list of postal code validations
This commit will update the list of postal codes using the command
below:

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

The changes that broke existing tests were reverted.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-05-18 22:22:38 +02:00
Daniel Altenburg 6e2b3e599e
Update validation for Armenian postal codes
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>
2020-05-18 22:06:15 +02:00
Mateusz Burzyński a44f97f4b3
Add support for Caymanian postal code validation
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>
2020-05-18 21:59:02 +02:00
Bogus b7b67da31e
Update validation for Israeli postal codes
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>
2020-05-18 21:46:57 +02:00
Dylan T 3501192293
Report all errors when asserting with "Each" rule
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>
2020-05-18 21:18:13 +02:00
pathumhdes 7154e90522
Restore previous error handler when validation fails
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>
2020-05-18 15:26:06 +02:00
Daniel Altenburg 3463343b14
Fix ecuador postal code format to 6 digits
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2020-05-13 18:41:55 +02:00
Henrique Moody ec8874808f
Move "MaxAgeTest" to the correct directory
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-06-04 20:50:01 +02:00
Henrique Moody ef8a8f4b27
Turn LICENSE file into plain/text
There is no need for that file to be a Markdown, and it can be a plain
text file.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-23 16:21:34 +02:00
Henrique Moody 3093d79155
Allow to customize parameter stringifier
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>
2019-05-12 13:49:54 +02:00
Henrique Moody 00f61b9bdc
Move message formatting out of ValidationException
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>
2019-05-12 13:45:38 +02:00