Commit graph

1250 commits

Author SHA1 Message Date
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
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 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
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 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 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 72dd88144e
Update version of "respect/coding-standard"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-08-27 16:21:02 +02:00
The Respect Panda 314aa36e37 Update list of top-level domains 2020-08-23 00:24:43 +00: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
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
The Respect Panda 80f236bb90 Update list of top-level domains 2020-06-07 00:14:45 +00:00
The Respect Panda 83936a0c00
Update list of top-level domains 2020-06-03 09:40:10 +02:00
The Respect Panda 6eeacfce5a Update list of language codes 2020-05-31 00:11:47 +00:00
Henrique Moody 83b515d0a3
Configure GitHub workflow to update language codes
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-05-26 18:33:23 +02:00
Henrique Moody e0fbed32c9
Update list of currency codes
Also updates the script that updates the currency codes.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-05-20 15:02:44 +02:00
Henrique Moody 6f92132874
Update list of top-level domains
This commit will add the LLP, XN--MGBCPQ6GPA1A, XN--Q7CE6A and XN--QXA6A
top-level domains, and remove BNL, CARTIER, CHRYSLER, DODGE, DUNS,
EVERBANK, HONEYWELL, ISELECT, LADBROKES, LANCOME, LIAISON, MOBILY,
MOPAR, MOVISTAR, NADEX, PIAGET, SRT, STARHUB, TELEFONICA, UCONNECT,
VISTAPRINT, WARMAN, XN--ESTV75G and XN--MGBB9FBPOB top-level domains.

Below the Bash command I used to generate the new list:

curl https://data.iana.org/TLD/tlds-alpha-by-domain.txt |
  grep --invert-match '^#' |
  sed --regexp-extended "s,^,',; s/$/', /" |
  tr --delete '\n' |
  fold --width=72 --spaces

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-05-19 11:31:43 +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
Pierre-Antoine Guillaume 4d706b0845
Update docblock from "when" rule
The variable name in dynamic method when does not match variable name in When object.
2020-04-16 17:24:58 +02:00
Mikko Pesari 015e6d4a54 Fix Email validator when egulias/email-validator was not installed 2020-04-08 18:00:19 +03:00
Henrique Moody b9e73db494
Add support for PHP 7.4 version
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-04-04 22:29:03 +02:00
Henrique Moody 9a41f64479
Fix possible error when recursing exceptions
The method "current()" from NestedValidationException can return any
instance of ValidationException, but the implementation of
"getChildren()" requires it to return an instance of
"NestedValidationException".

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-04-04 21:01:30 +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 45d109fc83
Update list of currency codes
This commit will also create a Bash script to update that list in the
future.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-28 08:10:06 +02:00
Henrique Moody c51931679c
Update list of language code
This commit will also create a Bash script to update that list in the
future.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-28 08:02:57 +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 5c61c25680
Update TLD list to version 2019052600
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-26 13:12:16 +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
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 272f18dcf5
Apply "Symfony.Functions.ScopeOrder"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-11 20:00:19 +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 051866f75a
Make properties of "AbstractRelated" private
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>
2019-05-05 16:54:04 +02:00
Henrique Moody d58395626f
Remove exceptions from suvdivision code rules
The "SubdivisionCode" rule was refactored [1] and now it doesn't need
one rule per country.

This commit will also remove the exceptions that were supposed to be
removed before.

[1]: 718bacad04

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-05 14:55:11 +02:00
Henrique Moody 2ac0aecf0c
Fix some issues with the "KeyValue" rule
There are a couple of issues with the "KeyValue" rule:

* When using it with "Not" it does not fetch the exception from the rule
  that it creates during the validation.

* It creates a "Validator" rule, which means that it creates two rules
  (Validator and the real rule) every time it validates an input.

This commit will fix these two issues and also create integration tests
that will ensure its behavior in case of change.

Co-authored-by: Danilo Correa <danilosilva87@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-04-23 19:55:13 +02:00
Henrique Moody 718bacad04
Remove subdivision code rules per country
There is no much benefit from having individual rules for each country's
subdivision, quite the opposite. It increases the amount of code and
makes it hard to change the implementation of these rules. Right now,
the only sane way to change those rules is with a customized script.

This commit will remove the Subdivision Code rules per country and
instead will put that information into JSON files.

We both wouldn't like to keep this in this library anymore, and we are
considering having another library to deal with this data [1], but since
it seems like it may take some time, looks better to do it temporarily
here.

[1]: https://github.com/sokil/php-isocodes/issues/12

Co-authored-by: Mazen Touati <mazen_touati@hotmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-04-06 23:05:24 +02:00
Henrique Moody 1b844763a9
Improve message when nested "Not" rules fail
When using nested "Not" and "AllOf" rules Validation does not fetch the
message of the rule that failed, and instead it fetches the default
message in "AllOfException."

That is because "Not" cannot reach the rules inside "AllOf," making it
impossible to fetch the correct message.

This commit will improve that a bit but making "Not" deal directly with
the rule inside "AllOf" when it has only one rule.

Unfortunately, it will not fix all the issues. For example, when the
negated rule is an "AllOf" with multiple rules and it fails "Not" will
fetch only the first message.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-04-05 23:32:31 +02:00
Henrique Moody 51f157605d
Make "NotEmpty" a final class
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-04-05 20:28:58 +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 6040ddee42
Fix the case of the "@inheritDoc" tag
According to the official documentation [1] the correct way of writing
the "inheritDoc" tag is with the uppercase "D".

[1]: https://docs.phpdoc.org/guides/inheritance.html

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-04-05 19:02:12 +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
Daniel Alt 9bafee191d
Fix Irish postal code validation
Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2019-03-31 15:27:49 +02:00
Mazen Touati 9dca4bde60
Add inclusive messages to LengthException 2019-03-31 00:50:24 +01:00
Paulo Dias f246939221 Fix bug to validate "01234567890" input in CPF rule 2019-03-29 13:26:36 -03:00
Henrique Moody 166501804f
Refactor "Zend" rule
- Only create objects that are instantiable.

- Validate if validator is a valid Zend Validator after its creation.

- Parse messages from Zend Validator on "assert()" and "check()."

- Upgrade supported version of Zend Validator: version 2.0 has some PHP
  deprecations therefore there is no used to support it.

Co-authored-by: Danilo Correa <danilosilva87@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-03-10 22:13:16 +01: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
Henrique Moody b340b74cfd
Make classes final
The rules "AllOf," "NotEmpty," and "Xdigit" cannot be final because
other rules extend them.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-17 20:13:27 +01:00
Henrique Moody c60ca7937b
Update the Coding Standards
This commit will add a couple of rules that we already use but also
introduce new ones and make sure all the code is in accordance with the
new coding standards.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-17 19:52:26 +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
Danilo Correa 9f9b33a36c
Apply contribution guidelines to "NfeAccessKey" 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 3723a124c8
Fix NoWhitespaceException typo 2019-02-10 12:52:24 +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
Danilo Correa fc433ad449
Apply contribution guidelines to "Graph" rule
After writing the integration tests of the "Graph" 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-10 12:25:11 +01:00
Danilo Correa ffc349cb03
Apply contribution guidelines to "Consonant" rule
After seeing the integration tests of the "Consonant" 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-10 12:21:40 +01:00
Danilo Correa 74c3d1acc3
Apply contribution guidelines to "Cntrl" rule
After writing the integration tests of the "Cntrl" 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-10 12:21:09 +01:00
Henrique Moody 4ab037ed87
Apply "SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-09 14:24:08 +01:00
Henrique Moody 85e6af6fcd
Apply "SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-09 14:23:09 +01:00
Henrique Moody 81a77ae125
Apply "SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-09 14:22:31 +01:00