Fix possible error when recursing exceptions

The method "current()" from NestedValidationException can return any
instance of ValidationException, but the implementation of
"getChildren()" requires it to return an instance of
"NestedValidationException".

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2020-04-04 21:01:30 +02:00
parent ec8874808f
commit 9a41f64479
No known key found for this signature in database
GPG key ID: 221E9281655813A6

View file

@ -16,6 +16,7 @@ namespace Respect\Validation\Exceptions;
use ArrayIterator;
use Countable;
use RecursiveIterator;
use UnexpectedValueException;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
@ -48,7 +49,12 @@ final class RecursiveExceptionIterator implements RecursiveIterator, Countable
public function getChildren(): self
{
return new static($this->current());
$exception = $this->current();
if (!$exception instanceof NestedValidationException) {
throw new UnexpectedValueException();
}
return new static($exception);
}
/**