Commit graph

273 commits

Author SHA1 Message Date
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 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
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
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
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 b4ad2f6413
Change the PHP support to version 7.2 or aboce
Since there will still be secutiry support until 30 Nov 2020 and there
was something happening in Travis when generating coverage with newer
versions of PHP which I'm not in the mood to debug, I decided to change
the support again, this time to version 7.2.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-04-04 23:55:05 +02:00
Henrique Moody f4593b7479
Drop support for PHP < 7.3
I am about to release version 2.0, and it's been way too much time since
I created a MINOR or MAJOR version.

Because I don't know when will be the next time I will release the next
version and it is troublesome to keep support to old PHP versions, I
decided to only give support to the versions PHP is actively supporting.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-04-04 23:23:23 +02:00
Henrique Moody 2d0f56d9cb
Merge branch '1.1'
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>
2019-05-29 23:17:53 +02:00
Henrique Moody 8b8f7db713
Update list of subdivision codes
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>
2019-05-26 16:18:49 +02:00
Henrique Moody f580e187d0
Update list of Country Codes
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>
2019-05-26 14:59:41 +02:00
Henrique Moody 6a52b63bbb
Remove duplication amoung documentations
There is quite some duplication between the "README.md" file and the
"docs/index.md". This commit will separate what belongs to the
documentation and what is specific of the repository.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-22 21:07:26 +02:00
Henrique Moody b88da74f79
Update number of rules in the documentation
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-22 21:01:13 +02:00
Henrique Moody 1b146758ee
Upgrade supported PHP version in the documentation
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-22 20:59:22 +02:00
Henrique Moody 408d8e825b
Move "Message placeholder conversion" documentation
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-22 20:56:22 +02:00
Henrique Moody 5c0bd3a5da
Move "Message translation" documentation
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-22 20:56:09 +02:00
Henrique Moody 7be7f0f58c
Move "Custom rules" documentation
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-22 20:55:59 +02:00
Danilo Correa fbf82dc975
Replace removed rule from documentation
The "Age" was removed but the documentation was not completely updated.
2019-05-22 20:37:28 +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 ab602ae1bb
Improve how to customize the Factory
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>
2019-05-12 12:24:44 +02:00
Henrique Moody f3bc39066b
Make default templates non-static and protected
The only reason why those templates are static is so users can overwrite
the exception messages. That was useful when we didn't have a handy
translator, but now that we can define a translator through the Factory,
this is not needed anymore.

Besides, having those properties public adds complexity to the code.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-12 09:57:07 +02:00
Henrique Moody c522f6235c
Remove "IdentityCard" in favor of "PolishIdCard"
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>
2019-05-12 00:22:45 +02:00
Henrique Moody f23b3a522a
Remove "Vatin" in favor of "Nip"
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>
2019-05-11 23:44:10 +02:00
Henrique Moody 0417fea213
Fix confusion with some changelogs
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>
2019-05-11 21:44:44 +02:00
Henrique Moody 9c0f8dcfcc
Rename rule "Cntrl" to "Control"
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>
2019-05-11 19:35:14 +02:00
Henrique Moody 4db2b00f6c
Update list of rules in "list-of-rules.md"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-11 19:16:33 +02:00
Henrique Moody 10df3211f5
Add "Categorization" section to rule documentations
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-11 19:16:21 +02:00
Henrique Moody b815fdff92
Move documentation about "Comparable Values"
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>
2019-05-11 17:34:42 +02:00
Henrique Moody 6e4927a621
Fix broken links in "list-of-rules.md"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-11 17:30:04 +02:00
Henrique Moody 996b797db0
Add missing changelog entry in "Unique.md"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-11 17:28:35 +02:00
Henrique Moody 7b53d54931
Apply contribution guidelines to "No" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-04-05 20:25:00 +02:00
Henrique Moody 22f3f80f4c
Make some improvements to the "Roman" rule
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>
2019-04-05 20:15:46 +02:00
Henrique Moody cb528ae612
Apply contribution guidelines to "Xdigit" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-04-05 20:09:17 +02:00
Henrique Moody 18ce48371c
Allow hex RGB colors with 3 integers
This commit will also apply the contribution guidelines to the rule and
improve its  documentation.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-04-05 19:05:53 +02:00
Henrique Moody cd2390a9b0
Refactor "Domain" rule
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>
2019-04-05 18:57:22 +02:00
Henrique Moody 81ce5b090b
Merge branch '1.1' 2019-03-31 15:40:12 +02:00
Henrique Moody 1f6c821fb6
Refactor "Sorted" rule
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>
2019-03-10 18:31:03 +01:00
Danilo Correa 5444ab5b0a
Apply contribution guidelines to "Size" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2019-03-10 18:07:39 +01:00
Danilo Correa b98a7ac89b
Apply contribution guidelines to "Vowel" rule
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>
2019-03-10 18:07:39 +01:00
Danilo Correa 18bdd399d7
Apply contribution guidelines to "StartsWith" rule
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>
2019-03-10 18:07:39 +01:00
Danilo Correa d2c4912582
Apply contribution guidelines to "Space" rule
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>
2019-03-10 18:07:36 +01:00
Danilo Correa d63983e2d2
Apply contribution guidelines to "Slug" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-17 19:21:25 +01:00
Danilo Correa 540c0a4a17
Apply contribution guidelines to "Punct" rule
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>
2019-02-17 19:21:14 +01:00
Danilo Correa e62d4e145d
Apply contribution guidelines to "Phone" rule
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-17 19:21:14 +01:00
Henrique Moody 21aa8eec62
Apply contribution guidelines to "PostalCode" rule
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>
2019-02-17 19:21:14 +01:00
Mazen Touati 6d3eb6afed
Create "Iban" rule
The validation procedure is adhering to what is described in Wikipedia.

Link: https://en.wikipedia.org/wiki/International_Bank_Account_Number#Validating_the_IBAN
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-10 12:54:54 +01:00
Mazen Touati a8cb87217f
Make the ranges of emoji more accurate
The new ranges are now 100% accurate by not including any Unicode point
that is not defined into the reference file.

For example, in the old ranges there is this interval:

    [\x{3297}-\x{3299}]

That is not accurate because there is no "3298" Unicode point in the
specs. It may be used by another character and it will cause the check
to fail if the user included that particular character.

The new ranges for that previous example are now:

    \x{3297}
    \x{3299}

And so on...

This commit will make the ranges more accurate with maximum tolerance to
other charcters and also rename the constant name from "GROUPS" to
"RANGES" since they are ranges, not groups.
2019-02-10 12:44:51 +01:00
bagus erlang 120d924d8d
Fix coding standard of code in the "Feature guide" 2019-02-10 12:41:37 +01:00