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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
This commit will also apply the contribution guidelines to the rule and
improve its documentation.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>