Apply "SlevomatCodingStandard.TypeHints.TypeHintDeclaration"

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2019-02-07 21:22:10 +01:00
parent 7e11cc0027
commit c30603759e
No known key found for this signature in database
GPG key ID: 221E9281655813A6
163 changed files with 1033 additions and 467 deletions

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class AllOfException extends GroupedValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::NONE => 'All of the required rules must pass for {{name}}',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class AnyOfException extends NestedValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => 'At least one of these rules must pass for {{name}}',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class CntrlException extends FilteredValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only control characters',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class ConsonantException extends FilteredValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only consonants',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class DomainException extends NestedValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid domain',

View file

@ -24,6 +24,9 @@ namespace Respect\Validation\Exceptions;
*/
final class EmailException extends ValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be valid email',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class GraphException extends FilteredValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only graphical characters',

View file

@ -24,6 +24,9 @@ class GroupedValidationException extends NestedValidationException
public const NONE = 'none';
public const SOME = 'some';
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::NONE => 'All of the required rules must pass for {{name}}',
@ -35,6 +38,9 @@ class GroupedValidationException extends NestedValidationException
],
];
/**
* {@inheritdoc}
*/
protected function chooseTemplate(): string
{
$numRules = $this->getParam('passed');

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class HexRgbColorException extends ValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a hex RGB color',

View file

@ -19,7 +19,7 @@ namespace Respect\Validation\Exceptions;
class IdentityCardException extends ValidationException
{
/**
* @var array
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [

View file

@ -23,7 +23,7 @@ class KeySetException extends GroupedValidationException implements NonOmissible
public const STRUCTURE = 'structure';
/**
* @var array
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [

View file

@ -20,6 +20,9 @@ class KeyValueException extends ValidationException
{
public const COMPONENT = 'component';
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => 'Key {{name}} must be present',

View file

@ -21,7 +21,7 @@ use Respect\Validation\Exceptions\ValidationException;
class PlIdentityCardException extends ValidationException
{
/**
* @var array
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [

View file

@ -22,7 +22,7 @@ use Respect\Validation\Exceptions\ValidationException;
final class PlVatinException extends ValidationException
{
/**
* @var array
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [

View file

@ -55,10 +55,6 @@ class NestedValidationException extends ValidationException implements IteratorA
/**
* Adds a child to the exception.
*
* @param ValidationException $exception
*
* @return self
*/
public function addChild(ValidationException $exception): self
{
@ -71,8 +67,6 @@ class NestedValidationException extends ValidationException implements IteratorA
* Adds children to the exception.
*
* @param ValidationException[] $exceptions
*
* @return self
*/
public function addChildren(array $exceptions): self
{
@ -83,9 +77,6 @@ class NestedValidationException extends ValidationException implements IteratorA
return $this;
}
/**
* @return SplObjectStorage
*/
public function getIterator(): SplObjectStorage
{
$childrenExceptions = new SplObjectStorage();
@ -130,9 +121,9 @@ class NestedValidationException extends ValidationException implements IteratorA
* Once templates are passed it overwrites the templates of the given
* messages.
*
* @param array $templates
* @param string[]|string[][] $templates
*
* @return array
* @return string[]
*/
public function getMessages(array $templates = []): array
{
@ -164,8 +155,6 @@ class NestedValidationException extends ValidationException implements IteratorA
/**
* Returns a string with all the messages of the exception.
*
* @return string
*/
public function getFullMessage(): string
{
@ -221,6 +210,9 @@ class NestedValidationException extends ValidationException implements IteratorA
return !$childException instanceof NonOmissibleException;
}
/**
* @param string[] $templates
*/
private function renderMessage(ValidationException $exception, array $templates): string
{
if (isset($templates[$exception->getId()])) {
@ -230,6 +222,12 @@ class NestedValidationException extends ValidationException implements IteratorA
return $exception->getMessage();
}
/**
* @param string[] $templates
* @param mixed ...$ids
*
* @return string[]
*/
private function findTemplates(array $templates, ...$ids): array
{
while (count($ids) > 0) {

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class NfeAccessKeyException extends ValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid NFe access key',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
final class NifException extends ValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a NIF',

View file

@ -18,6 +18,9 @@ namespace Respect\Validation\Exceptions;
*/
class NoException extends ValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} is not considered as "No"',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class NoneOfException extends NestedValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => 'None of these rules must pass for {{name}}',

View file

@ -22,6 +22,9 @@ final class NotEmptyException extends ValidationException
{
public const NAMED = 'named';
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => 'The value must not be empty',
@ -33,6 +36,9 @@ final class NotEmptyException extends ValidationException
],
];
/**
* {@inheritdoc}
*/
protected function chooseTemplate(): string
{
if ($this->getParam('input') || $this->getParam('name')) {

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class OneOfException extends NestedValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => 'Only one of these rules must pass for {{name}}',

View file

@ -20,6 +20,9 @@ class OptionalException extends ValidationException
{
public const NAMED = 'named';
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => 'The value must be optional',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class PhoneException extends ValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid telephone number',

View file

@ -18,6 +18,9 @@ namespace Respect\Validation\Exceptions;
*/
class PostalCodeException extends ValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid postal code on {{countryCode}}',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class PunctException extends FilteredValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only punctuation characters',

View file

@ -22,6 +22,9 @@ use RecursiveIterator;
*/
class RecursiveExceptionIterator implements RecursiveIterator, Countable
{
/**
* @var ArrayIterator|ValidationException[]
*/
private $exceptions;
public function __construct(NestedValidationException $parent)
@ -56,7 +59,7 @@ class RecursiveExceptionIterator implements RecursiveIterator, Countable
return $this->exceptions->current();
}
public function key()
public function key(): int
{
return $this->exceptions->key();
}
@ -71,7 +74,7 @@ class RecursiveExceptionIterator implements RecursiveIterator, Countable
$this->exceptions->rewind();
}
public function valid()
public function valid(): bool
{
return $this->exceptions->valid();
}

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class RomanException extends ValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid roman number',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class SlugException extends ValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid slug',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class SortedException extends ValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be ordered',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class SpaceException extends FilteredValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only space characters',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class StartsWithException extends ValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must start with ({{startValue}})',

View file

@ -18,6 +18,9 @@ namespace Respect\Validation\Exceptions;
*/
class SubdivisionCodeException extends ValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid subdivision code for {{countryCode}}',

View file

@ -18,6 +18,9 @@ namespace Respect\Validation\Exceptions;
*/
class UrlException extends ValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a URL',

View file

@ -32,7 +32,7 @@ class ValidationException extends InvalidArgumentException implements Exception
/**
* Contains the default templates for exception message.
*
* @var array
* @var string[][]
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
@ -59,7 +59,7 @@ class ValidationException extends InvalidArgumentException implements Exception
private $mode = self::MODE_DEFAULT;
/**
* @var array
* @var mixed[]
*/
private $params = [];
@ -73,6 +73,10 @@ class ValidationException extends InvalidArgumentException implements Exception
*/
private $template;
/**
* @param mixed $input
* @param mixed[] $params
*/
public function __construct($input, string $id, array $params, callable $translator)
{
$this->input = $input;
@ -89,12 +93,18 @@ class ValidationException extends InvalidArgumentException implements Exception
return $this->id;
}
/**
* @return mixed[]
*/
public function getParams(): array
{
return $this->params;
}
public function getParam($name)
/**
* @return mixed|null
*/
public function getParam(string $name)
{
return $this->params[$name] ?? null;
}
@ -111,6 +121,9 @@ class ValidationException extends InvalidArgumentException implements Exception
$this->message = $this->createMessage();
}
/**
* @param mixed[] $params
*/
public function updateParams(array $params): void
{
$this->params = $params;
@ -151,7 +164,10 @@ class ValidationException extends InvalidArgumentException implements Exception
return call_user_func($this->translator, $template);
}
private function format($template, array $vars = []): string
/**
* @param mixed[] $vars
*/
private function format(string $template, array $vars = []): string
{
return preg_replace_callback(
'/{{(\w+)}}/',

View file

@ -20,7 +20,7 @@ namespace Respect\Validation\Exceptions;
final class VatinException extends ValidationException
{
/**
* @var array
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class VowelException extends FilteredValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only vowels',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class XdigitException extends FilteredValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} contain only hexadecimal digits',

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Exceptions;
*/
class ZendException extends NestedValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}}',

View file

@ -91,8 +91,6 @@ final class Factory
/**
* Define the default instance of the Factory.
*
* @param Factory $defaultInstance
*/
public static function setDefaultInstance(self $defaultInstance): void
{
@ -101,8 +99,6 @@ final class Factory
/**
* Returns the default instance of the Factory.
*
* @return Factory
*/
public static function getDefaultInstance(): self
{
@ -122,12 +118,9 @@ final class Factory
/**
* Creates a rule.
*
* @param string $ruleName
* @param array $arguments
* @param mixed[] $arguments
*
* @throws ComponentException
*
* @return Validatable
*/
public function rule(string $ruleName, array $arguments = []): Validatable
{
@ -150,14 +143,10 @@ final class Factory
/**
* Creates an exception.
*
*
* @param Validatable $validatable
* @param mixed $input
* @param array $extraParams
* @param mixed[] $extraParams
*
* @throws ComponentException
*
* @return ValidationException
*/
public function exception(Validatable $validatable, $input, array $extraParams = []): ValidationException
{
@ -182,14 +171,8 @@ final class Factory
/**
* Creates a reflection based on class name.
*
*
* @param string $name
* @param string $parentName
*
* @throws InvalidClassException
* @throws ReflectionException
*
* @return ReflectionClass
*/
private function createReflectionClass(string $name, string $parentName): ReflectionClass
{
@ -210,10 +193,10 @@ final class Factory
*
* Ensure namespaces are in the right format and contain the default namespaces.
*
* @param array $namespaces
* @param array $defaultNamespaces
* @param string[] $namespaces
* @param string[] $defaultNamespaces
*
* @return array
* @return string[]
*/
private function filterNamespaces(array $namespaces, array $defaultNamespaces): array
{
@ -232,15 +215,11 @@ final class Factory
/**
* Creates a Validation exception.
*
* @param string $exceptionName
* @param string $id
* @param mixed $input
* @param array $params
* @param mixed[] $params
*
* @throws InvalidClassException
* @throws ReflectionException
*
* @return ValidationException
*/
private function createValidationException(
string $exceptionName,
@ -259,10 +238,7 @@ final class Factory
}
/**
* @param Validatable $validatable
* @param ReflectionClass $reflection
*
* @return array
* @return mixed[]
*/
private function extractPropertiesValues(Validatable $validatable, ReflectionClass $reflection): array
{

View file

@ -62,10 +62,8 @@ trait CanCompareValues
*
* @param mixed $left
* @param mixed $right
*
* @return bool
*/
private function isAbleToCompareValues($left, $right)
private function isAbleToCompareValues($left, $right): bool
{
return is_scalar($left) === is_scalar($right);
}

View file

@ -22,11 +22,6 @@ trait CanValidateDateTime
{
/**
* Finds whether a value is a valid date/time in a specific format.
*
* @param string $format
* @param string $value
*
* @return bool
*/
private function isDateTime(string $format, string $value): bool
{
@ -48,7 +43,10 @@ trait CanValidateDateTime
return true;
}
private function isDateTimeParsable(array $info)
/**
* @param int[] $info
*/
private function isDateTimeParsable(array $info): bool
{
return 0 === $info['error_count'] && 0 === $info['warning_count'];
}
@ -58,7 +56,10 @@ trait CanValidateDateTime
return preg_match('/[djSFmMnYy]/', $format) > 0;
}
private function isDateInformation(array $info)
/**
* @param mixed[] $info
*/
private function isDateInformation(array $info): bool
{
if ($info['day']) {
return checkdate((int) $info['month'], $info['day'], (int) $info['year']);

View file

@ -28,8 +28,6 @@ trait CanValidateIterable
* Returns whether the value is iterable or not.
*
* @param mixed $value
*
* @return bool
*/
public function isIterable($value): bool
{

View file

@ -24,8 +24,6 @@ trait CanValidateUndefined
* Finds whether the value is undefined or not.
*
* @param mixed $value
*
* @return bool
*/
private function isUndefined($value): bool
{

View file

@ -46,9 +46,6 @@ abstract class AbstractAge extends AbstractRule
/**
* Initializes the rule.
*
* @param int $age
* @param string|null $format
*/
public function __construct(int $age, string $format = null)
{
@ -61,11 +58,6 @@ abstract class AbstractAge extends AbstractRule
* Should compare the current base date with the given one.
*
* The dates are represented as integers in the format "Ymd".
*
* @param int $baseDate
* @param int $givenDate
*
* @return bool
*/
abstract protected function compare(int $baseDate, int $givenDate): bool;

View file

@ -59,8 +59,6 @@ abstract class AbstractComparison extends AbstractRule
*
* @param mixed $left
* @param mixed $right
*
* @return bool
*/
abstract protected function compare($left, $right): bool;
}

View file

@ -35,8 +35,6 @@ abstract class AbstractComposite extends AbstractRule
/**
* Initializes the rule adding other rules to the stack.
*
* @param Validatable ...$rules
*/
public function __construct(Validatable ...$rules)
{
@ -64,8 +62,6 @@ abstract class AbstractComposite extends AbstractRule
/**
* Append a rule into the stack of rules.
*
* @param Validatable $rule
*
* @return AbstractComposite
*/
public function addRule(Validatable $rule): self

View file

@ -32,15 +32,14 @@ abstract class AbstractEnvelope extends AbstractRule
private $validatable;
/**
* @var array
* @var mixed[]
*/
private $parameters;
/**
* Initializes the rule.
*
* @param Validatable $validatable
* @param array $parameters
* @param mixed[] $parameters
*/
public function __construct(Validatable $validatable, array $parameters = [])
{

View file

@ -31,8 +31,6 @@ abstract class AbstractFilterRule extends AbstractRule
/**
* Initializes the rule with a list of characters to be ignored by the validation.
*
* @param string ...$additionalChars
*/
public function __construct(string ...$additionalChars)
{

View file

@ -34,8 +34,6 @@ abstract class AbstractLocaleWrapper extends AbstractWrapper
/**
* Initializes the rule.
*
* @param string $countryCode
*
* @throws ComponentException when country is not supported
*/
public function __construct(string $countryCode)
@ -52,8 +50,6 @@ abstract class AbstractLocaleWrapper extends AbstractWrapper
/**
* Returns the class name based on the identifier.
*
* @return string
*/
abstract protected function getSuffix(): string;
}

View file

@ -26,17 +26,37 @@ use function is_scalar;
*/
abstract class AbstractRelated extends AbstractRule
{
/**
* @var bool
*/
public $mandatory = true;
/**
* @var mixed
*/
public $reference = '';
/**
* @var Validatable|null
*/
public $validator;
/**
* @param mixed $input
*/
abstract public function hasReference($input): bool;
/**
* @param mixed $input
*
* @return mixed
*/
abstract public function getReferenceValue($input);
public function __construct($reference, Validatable $validator = null, $mandatory = true)
/**
* @param mixed $reference
*/
public function __construct($reference, Validatable $validator = null, bool $mandatory = true)
{
if (is_scalar($reference)) {
$this->setName((string) $reference);
@ -50,6 +70,9 @@ abstract class AbstractRelated extends AbstractRule
$this->mandatory = $mandatory;
}
/**
* {@inheritdoc}
*/
public function setName(string $name): Validatable
{
parent::setName($name);
@ -61,6 +84,9 @@ abstract class AbstractRelated extends AbstractRule
return $this;
}
/**
* {@inheritdoc}
*/
public function assert($input): void
{
$hasReference = $this->hasReference($input);
@ -79,6 +105,9 @@ abstract class AbstractRelated extends AbstractRule
}
}
/**
* {@inheritdoc}
*/
public function check($input): void
{
$hasReference = $this->hasReference($input);
@ -89,6 +118,9 @@ abstract class AbstractRelated extends AbstractRule
$this->decision('check', $hasReference, $input);
}
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
$hasReference = $this->hasReference($input);
@ -99,7 +131,10 @@ abstract class AbstractRelated extends AbstractRule
return $this->decision('validate', $hasReference, $input);
}
private function decision(string $type, bool $hasReference, $input)
/**
* @param mixed $input
*/
private function decision(string $type, bool $hasReference, $input): bool
{
return (!$this->mandatory && !$hasReference)
|| (is_null($this->validator)

View file

@ -25,15 +25,27 @@ use Respect\Validation\Validatable;
*/
abstract class AbstractRule implements Validatable
{
/**
* @var string|null
*/
protected $name;
/**
* @var string|null
*/
protected $template;
public function __invoke($input)
/**
* @param mixed$input
*/
public function __invoke($input): bool
{
return $this->validate($input);
}
/**
* {@inheritdoc}
*/
public function assert($input): void
{
if ($this->validate($input)) {
@ -43,21 +55,33 @@ abstract class AbstractRule implements Validatable
throw $this->reportError($input);
}
/**
* {@inheritdoc}
*/
public function check($input): void
{
$this->assert($input);
}
/**
* {@inheritdoc}
*/
public function getName(): ?string
{
return $this->name;
}
/**
* {@inheritdoc}
*/
public function reportError($input, array $extraParams = []): ValidationException
{
return Factory::getDefaultInstance()->exception($this, $input, $extraParams);
}
/**
* {@inheritdoc}
*/
public function setName(string $name): Validatable
{
$this->name = $name;
@ -65,6 +89,9 @@ abstract class AbstractRule implements Validatable
return $this;
}
/**
* {@inheritdoc}
*/
public function setTemplate(string $template): Validatable
{
$this->template = $template;

View file

@ -25,7 +25,7 @@ abstract class AbstractSearcher extends AbstractRule
use CanValidateUndefined;
/**
* @return array
* @return mixed[]
*/
abstract protected function getDataSource(): array;

View file

@ -30,8 +30,6 @@ abstract class AbstractWrapper extends AbstractRule
/**
* Initializes the rule.
*
* @param Validatable $validatable
*/
public function __construct(Validatable $validatable)
{

View file

@ -22,6 +22,9 @@ use Respect\Validation\Exceptions\GroupedValidationException;
*/
class AllOf extends AbstractComposite
{
/**
* {@inheritdoc}
*/
public function assert($input): void
{
$exceptions = $this->getAllThrownExceptions($input);
@ -41,6 +44,9 @@ class AllOf extends AbstractComposite
}
}
/**
* {@inheritdoc}
*/
public function check($input): void
{
foreach ($this->getRules() as $rule) {
@ -48,6 +54,9 @@ class AllOf extends AbstractComposite
}
}
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
foreach ($this->getRules() as $rule) {

View file

@ -23,6 +23,9 @@ use Respect\Validation\Exceptions\ValidationException;
*/
class AnyOf extends AbstractComposite
{
/**
* {@inheritdoc}
*/
public function assert($input): void
{
$validators = $this->getRules();
@ -38,6 +41,9 @@ class AnyOf extends AbstractComposite
}
}
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
foreach ($this->getRules() as $v) {
@ -49,6 +55,9 @@ class AnyOf extends AbstractComposite
return false;
}
/**
* {@inheritdoc}
*/
public function check($input): void
{
foreach ($this->getRules() as $v) {

View file

@ -26,17 +26,15 @@ use Respect\Validation\Validatable;
*/
final class Attribute extends AbstractRelated
{
public function __construct(string $reference, Validatable $validator = null, $mandatory = true)
public function __construct(string $reference, Validatable $validator = null, bool $mandatory = true)
{
parent::__construct($reference, $validator, $mandatory);
}
/**
* @param object $input
* {@inheritdoc}
*
* @throws ReflectionException
*
* @return mixed
*/
public function getReferenceValue($input)
{
@ -47,7 +45,7 @@ final class Attribute extends AbstractRelated
}
/**
* @param object $input
* {@inheritdoc}
*/
public function hasReference($input): bool
{

View file

@ -40,11 +40,8 @@ final class Base extends AbstractRule
/**
* Initializes the Base rule.
*
* @param int $base
* @param string $chars
*/
public function __construct(int $base, $chars = null)
public function __construct(int $base, string $chars = null)
{
if (!is_null($chars)) {
$this->chars = $chars;

View file

@ -41,9 +41,6 @@ final class Call extends AbstractRule
/**
* Initializes the rule with the callable to be executed after the input is passed.
*
* @param callable $callable
* @param Validatable $rule
*/
public function __construct(callable $callable, Validatable $rule)
{
@ -101,6 +98,9 @@ final class Call extends AbstractRule
return true;
}
/**
* @param mixed $input
*/
private function setErrorHandler($input): void
{
set_error_handler(function () use ($input): void {

View file

@ -30,14 +30,13 @@ final class Callback extends AbstractRule
public $callback;
/**
* @var array
* @var mixed[]
*/
public $arguments;
/**
* Initializes the rule.
*
* @param callable $callback
* @param mixed ...$arguments
*/
public function __construct(callable $callback, ...$arguments)

View file

@ -36,8 +36,6 @@ final class Charset extends AbstractRule
/**
* Initializes the rule.
*
* @param string ...$charset
*
* @throws ComponentException
*/
public function __construct(string ...$charset)

View file

@ -26,7 +26,7 @@ final class ContainsAny extends AbstractEnvelope
/**
* Initializes the rule.
*
* @param array $needles At least one of the values provided must be found in input string or array
* @param mixed[] $needles At least one of the values provided must be found in input string or array
* @param bool $identical Defines whether the value should be compared strictly, when validating array
*/
public function __construct(array $needles, bool $identical = false)
@ -37,6 +37,11 @@ final class ContainsAny extends AbstractEnvelope
);
}
/**
* @param mixed[] $needles
*
* @return Contains[]
*/
private function getRules(array $needles, bool $identical): array
{
return array_map(

View file

@ -330,8 +330,6 @@ final class CountryCode extends AbstractSearcher
/**
* Initializes the rule.
*
* @param string $set
*
* @throws ComponentException If $set is not a valid set
*/
public function __construct(string $set = self::ALPHA2)

View file

@ -88,8 +88,6 @@ final class CreditCard extends AbstractRule
/**
* Initializes the rule.
*
* @param string $brand
*
* @throws ComponentException
*/
public function __construct(string $brand = self::ANY)

View file

@ -42,8 +42,6 @@ final class Date extends AbstractRule
/**
* Initializes the rule.
*
* @param string $format
*
* @throws ComponentException
*/
public function __construct(string $format = 'Y-m-d')

View file

@ -39,8 +39,6 @@ final class DateTime extends AbstractRule
/**
* Initializes the rule.
*
* @param string|null $format
*/
public function __construct(string $format = null)
{

View file

@ -15,6 +15,7 @@ namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\DomainException;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validatable;
/**
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
@ -25,13 +26,23 @@ use Respect\Validation\Exceptions\ValidationException;
*/
class Domain extends AbstractComposite
{
/**
* @var Validatable
*/
protected $tld;
/**
* @var Validatable[]
*/
protected $checks = [];
/**
* @var AllOf
*
*/
protected $otherParts;
public function __construct($tldCheck = true)
public function __construct(bool $tldCheck = true)
{
$this->checks[] = new NoWhitespace();
$this->checks[] = new Contains('.');
@ -52,7 +63,7 @@ class Domain extends AbstractComposite
parent::__construct();
}
public function tldCheck($do = true)
public function tldCheck(bool $do = true): void
{
if (true === $do) {
$this->tld = new Tld();
@ -65,10 +76,11 @@ class Domain extends AbstractComposite
new Length(2, null)
);
}
return true;
}
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
foreach ($this->checks as $chk) {
@ -91,6 +103,9 @@ class Domain extends AbstractComposite
return true;
}
/**
* {@inheritdoc}
*/
public function assert($input): void
{
$exceptions = [];
@ -115,7 +130,11 @@ class Domain extends AbstractComposite
}
}
protected function collectAssertException(&$exceptions, $validator, $input): void
/**
* @param ValidationException[] $exceptions
* @param mixed $input
*/
protected function collectAssertException(array &$exceptions, Validatable $validator, $input): void
{
try {
$validator->assert($input);
@ -124,6 +143,9 @@ class Domain extends AbstractComposite
}
}
/**
* {@inheritdoc}
*/
public function check($input): void
{
foreach ($this->checks as $chk) {

View file

@ -37,8 +37,6 @@ final class Each extends AbstractRule
/**
* Initializes the constructor.
*
* @param Validatable $rule
*/
public function __construct(Validatable $rule)
{

View file

@ -39,8 +39,6 @@ final class Email extends AbstractRule
* Initializes the rule assigning the EmailValidator instance.
*
* If the EmailValidator instance is not defined, tries to create one.
*
* @param EmailValidator $validator
*/
public function __construct(EmailValidator $validator = null)
{

View file

@ -42,7 +42,6 @@ final class EndsWith extends AbstractRule
/**
* @param mixed $endValue
* @param bool $identical
*/
public function __construct($endValue, bool $identical = false)
{
@ -62,6 +61,9 @@ final class EndsWith extends AbstractRule
return $this->validateEquals($input);
}
/**
* @param mixed $input
*/
private function validateEquals($input): bool
{
if (is_array($input)) {
@ -74,6 +76,9 @@ final class EndsWith extends AbstractRule
return mb_strripos($input, $this->endValue, -1, $encoding) === $endPosition;
}
/**
* @param mixed $input
*/
private function validateIdentical($input): bool
{
if (is_array($input)) {

View file

@ -33,8 +33,6 @@ final class Extension extends AbstractRule
/**
* Initializes the rule.
*
* @param string $extension
*/
public function __construct(string $extension)
{

View file

@ -33,8 +33,6 @@ final class Factor extends AbstractRule
/**
* Initializes the rule.
*
* @param int $dividend
*/
public function __construct(int $dividend)
{

View file

@ -42,7 +42,6 @@ final class FilterVar extends AbstractEnvelope
/**
* Initializes the rule.
*
* @param int $filter
* @param mixed $options
*
* @throws ComponentException

View file

@ -19,6 +19,9 @@ namespace Respect\Validation\Rules;
*/
class HexRgbColor extends Xdigit
{
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
if (!is_string($input)) {

View file

@ -35,8 +35,6 @@ final class Image extends AbstractRule
/**
* Initializes the rule.
*
* @param finfo|null $fileInfo
*/
public function __construct(finfo $fileInfo = null)
{

View file

@ -28,7 +28,7 @@ use function mb_strpos;
final class In extends AbstractRule
{
/**
* @var array|string
* @var mixed[]|string
*/
private $haystack;
@ -40,8 +40,7 @@ final class In extends AbstractRule
/**
* Initializes the rule with the haystack and optionally compareIdentical flag.
*
* @param mixed $haystack
* @param bool $compareIdentical
* @param mixed[]|string $haystack
*/
public function __construct($haystack, bool $compareIdentical = false)
{
@ -49,6 +48,9 @@ final class In extends AbstractRule
$this->compareIdentical = $compareIdentical;
}
/**
* @param mixed $input
*/
private function validateEquals($input): bool
{
if (is_array($this->haystack)) {
@ -64,6 +66,9 @@ final class In extends AbstractRule
return false !== mb_stripos($this->haystack, $inputString, 0, mb_detect_encoding($inputString));
}
/**
* @param mixed $input
*/
private function validateIdentical($input): bool
{
if (is_array($this->haystack)) {

View file

@ -29,8 +29,6 @@ final class Instance extends AbstractRule
/**
* Initializes the rule with the expected instance name.
*
* @param string $instanceName
*/
public function __construct(string $instanceName)
{

View file

@ -27,6 +27,9 @@ use function is_float;
*/
final class IntVal extends AbstractRule
{
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
if (is_float($input) || is_bool($input)) {

View file

@ -68,9 +68,6 @@ final class Ip extends AbstractRule
/**
* Initializes the rule defining the range and some options for filter_var().
*
* @param string $range
* @param int|null $options
*
* @throws ComponentException In case the range is invalid
*/
public function __construct(string $range = '*', int $options = null)

View file

@ -23,7 +23,10 @@ use Respect\Validation\Validatable;
*/
class Key extends AbstractRelated
{
public function __construct($reference, Validatable $referenceValidator = null, $mandatory = true)
/**
* @param mixed $reference
*/
public function __construct($reference, Validatable $referenceValidator = null, bool $mandatory = true)
{
if (!is_scalar($reference) || '' === $reference) {
throw new ComponentException('Invalid array key name');
@ -31,11 +34,17 @@ class Key extends AbstractRelated
parent::__construct($reference, $referenceValidator, $mandatory);
}
/**
* {@inheritdoc}
*/
public function getReferenceValue($input)
{
return $input[$this->reference];
}
/**
* {@inheritdoc}
*/
public function hasReference($input): bool
{
return is_array($input) && array_key_exists($this->reference, $input);

View file

@ -24,6 +24,9 @@ use Respect\Validation\Exceptions\ComponentException;
*/
class KeyNested extends AbstractRelated
{
/**
* {@inheritdoc}
*/
public function hasReference($input): bool
{
try {
@ -35,12 +38,21 @@ class KeyNested extends AbstractRelated
return true;
}
private function getReferencePieces()
/**
* @return string[]
*/
private function getReferencePieces(): array
{
return explode('.', rtrim((string) $this->reference, '.'));
}
private function getValueFromArray($array, $key)
/**
* @param mixed[] $array
* @param mixed $key
*
* @return mixed
*/
private function getValueFromArray(array $array, $key)
{
if (!array_key_exists($key, $array)) {
$message = sprintf('Cannot select the key %s from the given array', $this->reference);
@ -50,7 +62,29 @@ class KeyNested extends AbstractRelated
return $array[$key];
}
private function getValueFromObject($object, $property)
/**
* @param mixed $key
*
* @return mixed
*/
private function getValueFromArrayAccess(ArrayAccess $array, $key)
{
if (!$array->offsetExists($key)) {
$message = sprintf('Cannot select the key %s from the given array', $this->reference);
throw new ComponentException($message);
}
return $array->offsetGet($key);
}
/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
*
* @param object $object
*
* @return mixed
*/
private function getValueFromObject($object, string $property)
{
if (empty($property) || !property_exists($object, $property)) {
$message = sprintf('Cannot select the property %s from the given object', $this->reference);
@ -60,12 +94,22 @@ class KeyNested extends AbstractRelated
return $object->{$property};
}
/**
* @param mixed $value
* @param mixed $key
*
* @return mixed
*/
private function getValue($value, $key)
{
if (is_array($value) || $value instanceof ArrayAccess) {
if (is_array($value)) {
return $this->getValueFromArray($value, $key);
}
if ($value instanceof ArrayAccess) {
return $this->getValueFromArrayAccess($value, $key);
}
if (is_object($value)) {
return $this->getValueFromObject($value, $key);
}
@ -74,6 +118,9 @@ class KeyNested extends AbstractRelated
throw new ComponentException($message);
}
/**
* {@inheritdoc}
*/
public function getReferenceValue($input)
{
if (is_scalar($input)) {

View file

@ -30,7 +30,7 @@ use function is_array;
final class KeySet extends AbstractWrapper
{
/**
* @var array
* @var mixed[]
*/
private $keys;
@ -53,11 +53,7 @@ final class KeySet extends AbstractWrapper
}
/**
* @param Validatable $validatable
*
* @throws ComponentException
*
* @return Key
*/
private function getKeyRule(Validatable $validatable): Key
{
@ -74,8 +70,6 @@ final class KeySet extends AbstractWrapper
}
/**
* @param Key $rule
*
* @return mixed
*/
private function getKeyReference(Key $rule)
@ -84,11 +78,9 @@ final class KeySet extends AbstractWrapper
}
/**
* @param array $input
*
* @return bool
* @param mixed $input
*/
private function hasValidStructure($input)
private function hasValidStructure($input): bool
{
if (!is_array($input)) {
return false;

View file

@ -15,6 +15,7 @@ namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validatable;
use Respect\Validation\Validator;
/**
@ -22,20 +23,36 @@ use Respect\Validation\Validator;
*/
class KeyValue extends AbstractRule
{
/**
* @var int|string
*/
public $comparedKey;
/**
* @var string
*/
public $ruleName;
/**
* @var int|string
*/
public $baseKey;
public function __construct($comparedKey, $ruleName, $baseKey)
/**
* @param int|string $comparedKey
* @param int|string $baseKey
*/
public function __construct($comparedKey, string $ruleName, $baseKey)
{
$this->comparedKey = $comparedKey;
$this->ruleName = $ruleName;
$this->baseKey = $baseKey;
}
private function getRule($input)
/**
* @param mixed $input
*/
private function getRule($input): Validatable
{
if (!isset($input[$this->comparedKey])) {
throw $this->reportError($this->comparedKey);
@ -55,7 +72,7 @@ class KeyValue extends AbstractRule
return $rule;
}
private function overwriteExceptionParams(ValidationException $exception)
private function overwriteExceptionParams(ValidationException $exception): ValidationException
{
$params = [];
foreach ($exception->getParams() as $key => $value) {
@ -72,6 +89,9 @@ class KeyValue extends AbstractRule
return $exception;
}
/**
* {@inheritdoc}
*/
public function assert($input): void
{
$rule = $this->getRule($input);
@ -83,6 +103,9 @@ class KeyValue extends AbstractRule
}
}
/**
* {@inheritdoc}
*/
public function check($input): void
{
$rule = $this->getRule($input);
@ -94,6 +117,9 @@ class KeyValue extends AbstractRule
}
}
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
try {

View file

@ -531,8 +531,6 @@ final class LanguageCode extends AbstractEnvelope
/**
* Initializes the rule defining the ISO 639 set.
*
* @param string $set
*
* @throws ComponentException
*/
public function __construct(string $set = self::ALPHA2)
@ -545,6 +543,9 @@ final class LanguageCode extends AbstractEnvelope
parent::__construct(new In($this->getHaystack($index), true), ['set' => $set]);
}
/**
* @return string[]
*/
private function getHaystack(int $index): array
{
return array_filter(array_column(self::LANGUAGE_CODES, $index));

View file

@ -33,8 +33,6 @@ final class LeapDate extends AbstractRule
/**
* Initializes the rule with the expected format.
*
* @param string $format
*/
public function __construct(string $format)
{

View file

@ -54,10 +54,6 @@ final class Length extends AbstractRule
/**
* Creates the rule with a minimum and maximum value.
*
* @param int|null $min
* @param int|null $max
* @param bool $inclusive TRUE by default
*
* @throws ComponentException
*/
public function __construct(int $min = null, int $max = null, bool $inclusive = true)
@ -84,6 +80,9 @@ final class Length extends AbstractRule
return $this->validateMin($length) && $this->validateMax($length);
}
/**
* @param mixed $input
*/
private function extractLength($input): ?int
{
if (is_string($input)) {

View file

@ -24,6 +24,9 @@ use Respect\Validation\Rules\AbstractRule;
*/
class PlIdentityCard extends AbstractRule
{
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
if (!preg_match('/^[A-Z0-9]{9}$/', $input)) {

View file

@ -27,6 +27,9 @@ use function str_split;
*/
final class PlVatin extends AbstractRule
{
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
if (!is_scalar($input)) {

View file

@ -39,9 +39,6 @@ final class Mimetype extends AbstractRule
/**
* Initializes the rule by defining the expected mimetype from the input.
*
* @param string $mimetype
* @param finfo $fileInfo
*/
public function __construct(string $mimetype, finfo $fileInfo = null)
{

View file

@ -25,9 +25,6 @@ final class Multiple extends AbstractRule
*/
public $multipleOf;
/**
* @param int $multipleOf
*/
public function __construct(int $multipleOf)
{
$this->multipleOf = $multipleOf;

View file

@ -22,17 +22,15 @@ use function str_split;
* Valida chave de acesso de NFe.
* Mais especificamente, relacionada ao DANFE.
*
* @see Manual de Integração do Contribuinte v4.0.1 (http://www.nfe.fazenda.gov.br)
*
* @author Andrey Knupp Vital <andreykvital@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
*/
class NfeAccessKey extends AbstractRule
{
/**
* @see Manual de Integração do Contribuinte v4.0.1 (http://www.nfe.fazenda.gov.br)
*
* @param string $input access key
*
* @return bool
* {@inheritdoc}
*/
public function validate($input): bool
{

View file

@ -67,7 +67,7 @@ final class Nif extends AbstractRule
return $this->validateDni((int) $number, $control);
}
private function validateCif(string $number, string $control)
private function validateCif(string $number, string $control): bool
{
$code = 0;
$position = 1;

View file

@ -18,7 +18,7 @@ namespace Respect\Validation\Rules;
*/
class No extends AbstractEnvelope
{
public function __construct($useLocale = false)
public function __construct(bool $useLocale = false)
{
$pattern = '^n(o(t|pe)?|ix|ay)?$';
if ($useLocale && defined('NOEXPR')) {

View file

@ -21,6 +21,9 @@ use Respect\Validation\Exceptions\NoneOfException;
*/
class NoneOf extends AbstractComposite
{
/**
* {@inheritdoc}
*/
public function assert($input): void
{
$exceptions = $this->getAllThrownExceptions($input);
@ -35,6 +38,9 @@ class NoneOf extends AbstractComposite
}
}
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
foreach ($this->getRules() as $rule) {

View file

@ -23,6 +23,9 @@ use Respect\Validation\Validatable;
*/
class Not extends AbstractRule
{
/**
* @var Validatable
*/
public $rule;
public function __construct(Validatable $rule)
@ -37,11 +40,17 @@ class Not extends AbstractRule
return parent::setName($name);
}
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
return false === $this->rule->validate($input);
}
/**
* {@inheritdoc}
*/
public function assert($input): void
{
if ($this->validate($input)) {
@ -59,7 +68,10 @@ class Not extends AbstractRule
throw $exception;
}
private function absorbAllOf(AllOf $rule, $input)
/**
* @param mixed $input
*/
private function absorbAllOf(AllOf $rule, $input): Validatable
{
$rules = $rule->getRules();
while (($current = array_shift($rules))) {

View file

@ -25,6 +25,9 @@ use function is_numeric;
*/
final class Odd extends AbstractRule
{
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
if (!is_numeric($input)) {

View file

@ -22,6 +22,9 @@ use Respect\Validation\Exceptions\ValidationException;
*/
class OneOf extends AbstractComposite
{
/**
* {@inheritdoc}
*/
public function assert($input): void
{
$validators = $this->getRules();
@ -37,6 +40,9 @@ class OneOf extends AbstractComposite
}
}
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
$rulesPassedCount = 0;
@ -51,6 +57,9 @@ class OneOf extends AbstractComposite
return 1 === $rulesPassedCount;
}
/**
* {@inheritdoc}
*/
public function check($input): void
{
$exceptions = [];

View file

@ -22,6 +22,9 @@ class Optional extends AbstractWrapper
{
use CanValidateUndefined;
/**
* {@inheritdoc}
*/
public function assert($input): void
{
if ($this->isUndefined($input)) {
@ -31,6 +34,9 @@ class Optional extends AbstractWrapper
parent::assert($input);
}
/**
* {@inheritdoc}
*/
public function check($input): void
{
if ($this->isUndefined($input)) {
@ -40,6 +46,9 @@ class Optional extends AbstractWrapper
parent::check($input);
}
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
if ($this->isUndefined($input)) {

View file

@ -23,7 +23,7 @@ use function sprintf;
*/
class Phone extends AbstractRule
{
protected function getPregFormat()
protected function getPregFormat(): string
{
return sprintf(
'/^\+?(%1$s)? ?(?(?=\()(\(%2$s\) ?%3$s)|([. -]?(%2$s[. -]*)?%3$s))$/',
@ -33,6 +33,9 @@ class Phone extends AbstractRule
);
}
/**
* {@inheritdoc}
*/
public function validate($input): bool
{
if (!is_scalar($input)) {

View file

@ -26,6 +26,8 @@ class PostalCode extends AbstractEnvelope
// phpcs:disable Generic.Files.LineLength.TooLong
/**
* @see http://download.geonames.org/export/dump/countryInfo.txt
*
* @var string[]
*/
public $postalCodes = [
'AD' => '/^(?:AD)*(\d{3})$/',
@ -191,7 +193,7 @@ class PostalCode extends AbstractEnvelope
];
// phpcs:enable Generic.Files.LineLength.TooLong
public function __construct($countryCode, CountryCode $countryCodeRule = null)
public function __construct(string $countryCode, CountryCode $countryCodeRule = null)
{
$countryCodeRule = $countryCodeRule ?: new CountryCode();
if (!$countryCodeRule->validate($countryCode)) {

View file

@ -32,8 +32,6 @@ final class Regex extends AbstractRule
/**
* Initializes the rule.
*
* @param string $regex
*/
public function __construct(string $regex)
{

Some files were not shown because too many files have changed in this diff Show more