Commit graph

2012 commits

Author SHA1 Message Date
Danilo Correa b8508e989a
Apply contribution guidelines to "Vatin" rule
As the "Vatin" rule is a "Plvatin" wrapper I considered using the same
unit tests from "PlVatin" to "Vatin".
2019-04-29 22:07:56 +02:00
Henrique Moody 5aba4c8889
Improve Travis configuration
This commit will put the quality assurance tools that Travis executes
into a different stage.

It will make the build time increase in approximately one minute, but
the configuration will be way more explicit than it is today.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-04-23 21:20:37 +02:00
Henrique Moody 1303a935bf
Convert case of "mikey179/vfsstream" package
Package names in Composer should not contain uppercase characters, and
after the version 2.0, it will error.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-04-23 20:13:12 +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 d2d4728883
Increase the number of rules we have in README.md
At this point, Validation has 151 available rules.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-04-06 23:46:25 +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 344b00cc07
Improve tests of the "Optional" rule
PHPT tests are expensive, having all and only the necessary tests in one
single file make more sense.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-04-05 20:46:38 +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 df5cb1e6d2
Uncomment comented code in "identityCard.phpt"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-03-10 18:50:31 +01:00
Henrique Moody 8bb49d8ab2
Unify integration tests
PHPT files are amazing, but they are also expensive to execute. Having
just one single file running the necessary tests is best than having one
file per test.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-03-10 18:49:01 +01:00
Henrique Moody d8f43589dc
Move integration test of "IntVal" to another directory
The integration tests for rules should stay in
"tests/integration/rules".

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-03-10 18:41:34 +01:00
Henrique Moody 6bcfba29d2
Remove extra tests for "Bsn" rule
There is already a test for this rule, therefore there is no need for
those 3 extra ones.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-03-10 18:41:12 +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
bagus erlang 120d924d8d
Fix coding standard of code in the "Feature guide" 2019-02-10 12:41:37 +01:00
bagus erlang ce0d658340
Fix coding standard of a code in "concrete-api.md" 2019-02-10 12:37:33 +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 688fbde552
Make PHPUnit tests final
Whenever is possible it is better to declare our classes as final. The
PHPUnit tests should not be extended, therefore there is no reason for
them to not be final.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-09 14:32:12 +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
Henrique Moody 454096c459
Apply "SlevomatCodingStandard.PHP.ShortList"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-09 14:21:23 +01:00
Henrique Moody 8f41ebec8d
Apply "SlevomatCodingStandard.Namespaces.UseSpacing"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-09 14:21:04 +01:00