Doing regex on phone numbers is not a great idea. This is a breaking
change, but a good one. Phone validation is now much stricter, and
allows choosing the country.
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>
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>
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>
Require "phpstan/phpstan" for development and add to the Travis CI
configuration file to execute the analysis when Travis executes the
build with the version 7.2 of PHP.
The level of the configuration is very week for now (just "1") and still
quite some changes had to be made in order to make the analysis pass. I
hope it does not take much time to increase the level of the strictness
of the analyses.
I tried to configure that before but because of dependencies with
"symfony/validator" it was not possible.
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>
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.
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.
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.
* `ExceptionInterface`: all Respect\Validation\Exceptions implement through inheritance
* `ValidatorExceptionInterface`: implemented only by AllOfException. This allows the end users to know when there has been a Validator exception rather than just any of our exceptions.
Fixed formatting issues
Created two new exception types
* Created ValidationExceptionInterface
* Created NestedValidationExceptionInterface which extends ValidationExceptionInterface
* Renamed from ValidatorExceptionInterface
* ValidationException implements ValidationExceptionInterface and ValidationExceptionTest checks for the implementation.
* AbstractNestedException implements NestedValidationExceptionInterface and AbstractNestedExceptionTest checks for the implementation.
* CheckExceptionsTest now checks all Rule exceptions to make sure they implement ValidationExceptionInterface
* ValidatorTest now contains test that shows that only ValidationExceptionInterface can be used reliably with `::check()`
* Updated documentation for new exception types
* Reworked examples to show how to catch the exception interfaces
Minor changes in readme.md and ExceptionInterfaces
* Removed `import` statements (hahaha)
* Renamed `$e` to `$exception`
* `ValidationExceptionInterface` now extends `ExceptionInterface`. Changed `ValidationException` to match