Commit graph

1842 commits

Author SHA1 Message Date
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 1b0be4c3a6
Remove documentation links in the repository
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-23 16:16:00 +02:00
Henrique Moody 32d796ed3d
Add warning about the stable version
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-22 21:16:57 +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 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 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 16376306f8
Use "Respect" coding standard
There are too many PHP_CodeSniffer configurations in this repository.

I have created "respect/coding-standard" to deal with all the
configuration so in this repository we only need to add "Respect" as our
PHP_CodeSniffer rule.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-11 20:51:39 +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 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 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 541fea9d7b
Fix syntax issue in ".travis.yml" file
On the step that was sending the code coverage to Scrutinizer, there is
an issue with the syntax after some changes in the Travis
configuration [1].

[1]: 5aba4c8889

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-05 16:52:56 +02:00
Henrique Moody 95b499b627
Apply "phpstan/phpstan-deprecation-rules" rules
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-05 15:18:09 +02:00
Henrique Moody d00ed89f3c
Apply "phpstan/phpstan-phpunit" rules
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-05 15:04:56 +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
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