mirror of
https://github.com/Respect/Validation.git
synced 2024-06-04 06:42:22 +02:00
Increate PHPStan level to 3
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
f52097075b
commit
b007284857
|
@ -13,6 +13,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
|
@ -36,7 +38,7 @@ class GroupedValidationException extends NestedValidationException
|
|||
protected function chooseTemplate(): string
|
||||
{
|
||||
$numRules = $this->getParam('passed');
|
||||
$numFailed = $this->getChildren()->count();
|
||||
$numFailed = count($this->getChildren());
|
||||
|
||||
return $numRules === $numFailed ? static::NONE : static::SOME;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
*/
|
||||
|
@ -41,7 +43,7 @@ class KeySetException extends GroupedValidationException implements NonOmissible
|
|||
*/
|
||||
protected function chooseTemplate(): string
|
||||
{
|
||||
if (0 === $this->getChildren()->count()) {
|
||||
if (0 === count($this->getChildren())) {
|
||||
return static::STRUCTURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,10 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
use function current;
|
||||
use IteratorAggregate;
|
||||
use RecursiveIteratorIterator;
|
||||
use function spl_object_hash;
|
||||
use SplObjectStorage;
|
||||
use const PHP_EOL;
|
||||
use function count;
|
||||
|
@ -37,21 +39,17 @@ use function str_repeat;
|
|||
class NestedValidationException extends ValidationException implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @var SplObjectStorage
|
||||
* @var ValidationException[]
|
||||
*/
|
||||
private $exceptions;
|
||||
private $exceptions = [];
|
||||
|
||||
/**
|
||||
* Returns the exceptions that are children of the exception.
|
||||
*
|
||||
* @return SplObjectStorage|ValidationException[]
|
||||
* @return ValidationException[]
|
||||
*/
|
||||
public function getChildren(): SplObjectStorage
|
||||
public function getChildren(): array
|
||||
{
|
||||
if (!$this->exceptions instanceof SplObjectStorage) {
|
||||
$this->exceptions = new SplObjectStorage();
|
||||
}
|
||||
|
||||
return $this->exceptions;
|
||||
}
|
||||
|
||||
|
@ -64,7 +62,7 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
*/
|
||||
public function addChild(ValidationException $exception): self
|
||||
{
|
||||
$this->getChildren()->attach($exception);
|
||||
$this->exceptions[spl_object_hash($exception)] = $exception;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -86,7 +84,7 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
}
|
||||
|
||||
/**
|
||||
* @return SplObjectStorage|ValidationException[]
|
||||
* @return SplObjectStorage
|
||||
*/
|
||||
public function getIterator(): SplObjectStorage
|
||||
{
|
||||
|
@ -205,13 +203,12 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
return false;
|
||||
}
|
||||
|
||||
if (1 !== $exception->getChildren()->count()) {
|
||||
if (1 !== count($exception->getChildren())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$exception->getChildren()->rewind();
|
||||
/** @var ValidationException $childException */
|
||||
$childException = $exception->getChildren()->current();
|
||||
$childException = current($exception->getChildren());
|
||||
if ($childException->getMessage() === $exception->getMessage()) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use RecursiveIterator;
|
||||
|
||||
|
@ -25,15 +26,15 @@ class RecursiveExceptionIterator implements RecursiveIterator, Countable
|
|||
|
||||
public function __construct(NestedValidationException $parent)
|
||||
{
|
||||
$this->exceptions = $parent->getChildren();
|
||||
$this->exceptions = new ArrayIterator($parent->getChildren());
|
||||
}
|
||||
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return $this->exceptions->count();
|
||||
}
|
||||
|
||||
public function hasChildren()
|
||||
public function hasChildren(): bool
|
||||
{
|
||||
if (!$this->valid()) {
|
||||
return false;
|
||||
|
@ -42,12 +43,15 @@ class RecursiveExceptionIterator implements RecursiveIterator, Countable
|
|||
return $this->current() instanceof NestedValidationException;
|
||||
}
|
||||
|
||||
public function getChildren()
|
||||
public function getChildren(): self
|
||||
{
|
||||
return new static($this->current());
|
||||
}
|
||||
|
||||
public function current()
|
||||
/**
|
||||
* @return ValidationException|NestedValidationException
|
||||
*/
|
||||
public function current(): ValidationException
|
||||
{
|
||||
return $this->exceptions->current();
|
||||
}
|
||||
|
|
|
@ -133,9 +133,12 @@ final class Factory
|
|||
{
|
||||
foreach ($this->rulesNamespaces as $namespace) {
|
||||
try {
|
||||
return $this
|
||||
/** @var Validatable $rule */
|
||||
$rule = $this
|
||||
->createReflectionClass($namespace.'\\'.ucfirst($ruleName), Validatable::class)
|
||||
->newInstanceArgs($arguments);
|
||||
|
||||
return $rule;
|
||||
} catch (ReflectionException $exception) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,8 @@ class Zend extends AbstractRule
|
|||
public function __construct($validator, $params = [])
|
||||
{
|
||||
if (is_object($validator)) {
|
||||
return $this->zendValidator = $validator;
|
||||
$this->zendValidator = $validator;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_string($validator)) {
|
||||
|
|
|
@ -219,7 +219,9 @@ final class Validator extends AllOf
|
|||
*/
|
||||
public function __call(string $ruleName, array $arguments): self
|
||||
{
|
||||
return $this->addRule(Factory::getDefaultInstance()->rule($ruleName, $arguments));
|
||||
$this->addRule(Factory::getDefaultInstance()->rule($ruleName, $arguments));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,7 +7,7 @@ parameters:
|
|||
- phpt
|
||||
ignoreErrors:
|
||||
- '/Call to an undefined static method Respect\\Validation\\Validator::iDoNotExistSoIShouldThrowException/'
|
||||
level: 2
|
||||
level: 3
|
||||
paths:
|
||||
- library/
|
||||
- tests/
|
||||
|
|
Loading…
Reference in a new issue