mirror of
https://github.com/Respect/Validation.git
synced 2026-03-18 08:09:51 +01:00
Fix issues after merging 1.1
These two branches are very different, therefore merging is becoming
very hard.
I decided to not put these changes together with 5750952 because it
seems easy to track these changes with a specific commit.
While working on this merge I realized that would make more sense to
create "AbstractComparison" to handle the rules that compare values.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
57509520a4
commit
0cdd8c4546
18 changed files with 131 additions and 133 deletions
|
|
@ -16,8 +16,11 @@ namespace Respect\Validation\Exceptions;
|
|||
use IteratorAggregate;
|
||||
use RecursiveIteratorIterator;
|
||||
use SplObjectStorage;
|
||||
use const PHP_EOL;
|
||||
use function count;
|
||||
use function implode;
|
||||
use function is_array;
|
||||
use function str_repeat;
|
||||
|
||||
class NestedValidationException extends ValidationException implements IteratorAggregate
|
||||
{
|
||||
|
|
@ -59,20 +62,7 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isOmissible(Exception $exception)
|
||||
{
|
||||
if (!$exception instanceof self) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$relatedExceptions = $exception->getRelated();
|
||||
$relatedExceptions->rewind();
|
||||
$childException = $relatedExceptions->current();
|
||||
|
||||
return 1 === $relatedExceptions->count() && !$childException instanceof NonOmissibleException;
|
||||
}
|
||||
|
||||
private function isSkippable(ValidationException $exception)
|
||||
private function isOmissible(Exception $exception): bool
|
||||
{
|
||||
if (!$exception instanceof self) {
|
||||
return false;
|
||||
|
|
@ -82,19 +72,17 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!$exception->hasCustomTemplate()) {
|
||||
$exception->getRelated()->rewind();
|
||||
$childException = $exception->getRelated()->current();
|
||||
if ($childException->getMessage() === $exception->getMessage()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasChildTemplate($exception);
|
||||
}
|
||||
if ($exception->hasCustomTemplate()) {
|
||||
return $childException->hasCustomTemplate();
|
||||
}
|
||||
|
||||
private function hasChildTemplate(self $exception)
|
||||
{
|
||||
$exception->getRelated()->rewind();
|
||||
$childException = $exception->getRelated()->current();
|
||||
|
||||
return $childException->getMessage() === $exception->getMessage();
|
||||
return !$childException instanceof NonOmissibleException;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -105,7 +93,6 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
$childrenExceptions = new SplObjectStorage();
|
||||
|
||||
$recursiveIteratorIterator = $this->getRecursiveIterator();
|
||||
$exceptionIterator = $recursiveIteratorIterator->getInnerIterator();
|
||||
|
||||
$lastDepth = 0;
|
||||
$lastDepthOriginal = 0;
|
||||
|
|
@ -181,7 +168,7 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
$messages = [];
|
||||
$leveler = 1;
|
||||
|
||||
if (!$this->isSkippable($this)) {
|
||||
if (!$this->isOmissible($this)) {
|
||||
$leveler = 0;
|
||||
$messages[] = sprintf('- %s', $this->getMessage());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue