Commit graph

1930 commits

Author SHA1 Message Date
Alexandre Gomes Gaigalas 15f148da24 Dusting off. See CHANGELOG.md for more details on this commit 2023-02-13 03:59:11 -03:00
Ayesh Karunaratne 746c755d14
Use json_validate in Rules\Json if available (#1394)
[`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.
2023-02-13 04:43:32 +00:00
Ondřej Vodáček bf4082d208
fix phpdoc type for KeySet constructor (#1365)
by @voda
2022-01-19 12:40:08 +02:00
Fabian Wiget 60566e2250
Fix E_DEPRECATED warning in IntVal rule on PHP 8.1 (#1374)
by @fabacino
2022-01-19 12:38:23 +02:00
Fabian Wiget 4847fe45ff
Fix check whether start and end address have been set in Ip rule (#1375)
by @fabacino
2022-01-19 12:36:13 +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 b78f602f0e
Revert "Use "sokil/php-isocodes" on LanguageCode"
This reverts commit 5450ef86a8.
2021-03-19 15:12:44 +01:00
Henrique Moody edbbe7fa5b
Revert "Use "sokil/php-isocodes" on CountryCode"
This reverts commit 2060207f44.
2021-03-19 15:12:44 +01:00
Henrique Moody be7e6672a1
Remove ignored error from PHPStan
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2021-03-19 15:12:43 +01:00
The Respect Panda 143420e79f Update list of top-level domains 2021-03-14 00:30:48 +00:00
Henrique Moody 51ad23e24c
Call mbstring functions without getting encoding
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>
2021-02-06 17:42:11 +01:00
Henrique Moody 3dcd859d98
Upgrade supported version of "egulias/email-validator"
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>
2021-02-06 16:29:39 +01:00
Henrique Moody 2060207f44
Use "sokil/php-isocodes" on CountryCode
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>
2021-02-06 15:53:39 +01:00
Henrique Moody 5450ef86a8
Use "sokil/php-isocodes" on LanguageCode
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>
2021-02-06 15:53:11 +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 f1be7302fc
Use the last MINOR version in updaters
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>
2021-02-06 13:02:07 +01:00
The Respect Panda 5a0b53831f
Update list of top-level domains 2021-02-06 12:56:35 +01:00
Henrique Moody 44a60f67d9
Fix PHPStan issues
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>
2021-02-06 12:51:56 +01:00
Henrique Moody 5ba7646925
Fix wrong changelog in the Decimal's documentation
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-10-05 13:01:29 +02:00
Henrique Moody 1eb5b9d3c5
Add "Decimal" link to related rules
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-10-05 12:49:42 +02: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 d532e942a5
Create mixin with rules names as methods
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>
2020-10-04 13:04:20 +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
The Respect Panda 444f105ea6
Update list of top-level domains 2020-10-04 12:11:09 +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
Henrique Moody e0c6f33c01
Only define filter_var options when it is valid
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>
2020-10-04 11:13:18 +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 a65980ca45
Remove PHP 8.0 from the build matrix
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-08-27 19:22:13 +02:00
Henrique Moody 80ff37ca7f
Configure continuous integration with GitHub actions
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>
2020-08-27 19:06:37 +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 5150428b27
Drop support for PHP 7.2
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-08-26 09:47:48 +02:00
The Respect Panda 314aa36e37 Update list of top-level domains 2020-08-23 00:24:43 +00:00
Henrique Moody f7a57a7f89
Update list of files to be exported by Git
Also, remove "couscous.yml" that is not being used anymore.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-07-29 10:35:36 +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
The Respect Panda 78d1ce404c Update list of top-level domains 2020-07-19 00:20:19 +00: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
The Respect Panda e2783d4220 Update list of top-level domains 2020-07-12 00:19:29 +00:00