Also add an extra validation to the rule, not allowing non-integers to
be considered as even numbers.
Co-Authored-By: Henrique Moody <henriquemoody@gmail.com>
This method change the behavior of "getMessages()" by changin the keys
of its return to the "id" of the specific exception that was triggered.
It also allows users to overwrite the templates by passing an array to
it.
This is being requested by many users for a long time. It took that long
because I was thinking too much about how to improve the old method
called "findMesssage()" that I didn't realize that it could be done in a
easier way with the "getMessages()".
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Make the ValidationException a little bit less mutable than before. All
its dependencies are now passed into the constructor.
This commit also make the Factory pass the translator to the exceptions
allowing to define the translator before the exception gets created.
This change is not the ideal one, later I would like to not need the
Singleton from the Factory to do that, but for now it seems like a good
approach.
One more thing that this commit does is to introduce the "id" for
Exceptions. Key can be either the defined "name" or the name of the rule
that throwed the exception. This method will be handy to identify
exceptions better.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The "MinimumAge" exception should use the "{{ name }}" placeholder
instead of the "{{ input }}" once that one can be either the input or a
user-defined name.
In the default message, the placeholder was using sprintf format, but
the correct way is to use "{{name}}". Also use the same style of the
other messages in the default message.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The "Between" rule is composed by two rules: "Min" and "Max". However it
has its specific exception and message. This commit makes it extend the
"AbstractEnvelop" class.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This abstract class is very similar to "AbstractWrapper" the difference
is that "AbstractWapper" will throw the exceptions of the rule that is
defined inside it, while "AbstractEnvelope" uses the exception of the
rule that extends it.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
Before this change every create rule must have an exception. This commit
allows to create rules without specific exceptions, so when the
exception of the rule is not found Validation uses ValidationException
instead.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
The "Between" rule was extending the "AllOf" rule and adding "Max" and
"Min" rules to the chain. Because of that, when the rule failed we could
get the "MinException" or the "MaxException" exception, and only if both
failed that we would get the "BetweenException".
With this change it will always get the "BetweenException" which makes
it more explicit.
Also, the "Between" is not using the same standard required in the
Contribution Guidelines.
The "Age" rule was removed because it had too many responsibilities.
Instead "MaximumAge" was created (since there is already "MinimumAge").
This commit also introduces "AbstractAge" rule that is been used in both
mentioned rules.
This commit also makes some changes in how the `DateTime` rule behaves,
by not accepting `DateTimeInterface` as valid when a format is given.
Also:
- Create `DateTimeHelper` to eliminate some code duplication;
- Create integration tests for `DateTime` rule;
- Rename "format" placeholder to "sample" in the message;
- Update documentation of "DateTime" rule.
Refactor `AbstractSearcher` class and its children. Also most of the
unnecessary logic that was on `AbstractSearcher` was put back into `In`
class.
This commit also updates all "SubdivisionCode" rules.
The script used to create the classes can be found on:
https://gist.github.com/henriquemoody/ec404f994a87b18c7771