Since the rule "GreaterThan" was created, there is no reason to allow
"Min" to not be inclusive.
Also apply contribution guidelines to the rule.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This changes the rule name in order to be more descriptive and explicit
(avoid abbreviation). It also applies the new contribution guidelines.
Signed-off-by: Emmerson Siqueira <emmersonsiqueira@gmail.com>
Since the rule "LessThan" was created, there is no reason to allow "Max"
to not be inclusive.
Also apply contribution guidelines to the rule.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
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 "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.
Due to this change it was possible to identify that NotEmptyException,
and NotOptionalException where not working as they should. A fix was
made along with this commit.
When executing `ValidationException::setTemplate()` using a template
key, it does not try to select the template, but instead it uses the
template key as the template itself.
In order to fix this behaviour, there is now a check for a key with the
defined template. In case the template was not found, use the defined
template as the template itself.
`NestedValidationException` should include all `AbstractRelated` rule
exceptions.
`AbstractRelated` rule failures always indicate an interesting nested
context, which should not be omitted from the final result.
`NonOmissibleExceptionInterface` is a marker interface for
exceptions thrown by instances of `AbstractRelated`, which
facilitates identification of those rules' exceptions with
`instanceof`.
If calling the method `getExceptionForPath()` when the exception was
nested but had no child it was returning null. This commit ensures that
it always return a valid exception.
Then using the `findMessages()` method, tries to use the method
`getRelatedByName()` before using the `findRelated()` method.
This change was made because since on `KeyNested` rule you may have
names with '.' we'll never get the proper exception using
`findRelated()`.
When you define the name for an `AbstractRelated` instance, you expect
that it also define the name for its child. But, when the child already
had a name the `AbstractRelated` was overwriting its name with the
`reference`.
When there is just one rule in the chain and the there is a defined
template for that, the expected behaviour when using the `check()`
method is to see the exception message with the defined template.
There were some cases when the exceptions was not displayed property
when using nested exception, this commit fix the problem and also
display messages in Markdown list.
Since we have NotOptional rule now, we must keep the same opposite
behaviour between these two rules.
This commit also improve and increase tests from Optional rule and
updates the documentation.
No tests was made for messages on MODE_DEFAULT because it's not possible
for a while since we don't have such much granularity control, but after
some fixes on Not rule, maybe we will be able to do that, that's why I
kept the messages on OptionalException.
Many changes were made on `ValidationException::stringify`:
- Add support for instances of `Exception`;
- Add support for instances of `Traversable`;
- Add support for resources;
- Improve `Array` conversion;
- Improve `Object` conversion;
- Improve conversion of all values by using JSON.
Now, all the parameters of the exception classes are just converted to
string when replacing parameters on exceptions, so the exception classes
now keep the original value of all parameters.
- setTemplate() with single validator should use template as main
message
- setTemplate() with multiple validators should use template as main
message
- setTemplate() with multiple validators should use template as full
message
- getFullMessage() should include all validation messages in a chain
- not() should work by builder
- countryCode()
- alwaysValid()
- alwaysInvalid()
- Issue #85: findMessages() should not trigger catchable fatal error
- keys as validator names
- Do not rely on nested validation exception interface for check