From 642602fd434df1cf32ef823bce94706c1ff1b34b Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Wed, 22 Jul 2020 14:02:39 +0200 Subject: [PATCH] Update version of PHPStan packages Some amazing features had to be ignored because it conflicts with out coring standards. I hope to soon fix them so we can use PHPStan to its fullest potential. Signed-off-by: Henrique Moody --- composer.json | 6 +++--- library/Exceptions/NestedValidationException.php | 11 +++++++---- .../Exceptions/RecursiveExceptionIterator.php | 4 ++-- library/Factory.php | 16 +++++++++++++--- library/Helpers/Subdivisions.php | 2 +- library/Rules/AbstractComposite.php | 2 +- library/Rules/AbstractRelated.php | 2 +- library/Rules/Callback.php | 15 ++++++++++++--- library/Rules/Cnh.php | 2 +- library/Rules/Cnpj.php | 2 +- library/Rules/Contains.php | 2 +- library/Rules/CreditCard.php | 2 +- library/Rules/EndsWith.php | 4 ++-- library/Rules/Factor.php | 2 +- library/Rules/Iban.php | 2 +- library/Rules/Image.php | 2 +- library/Rules/Imei.php | 2 +- library/Rules/In.php | 8 ++++---- library/Rules/Ip.php | 12 +++++++----- library/Rules/Isbn.php | 2 +- library/Rules/KeyValue.php | 2 +- library/Rules/Length.php | 2 +- library/Rules/Lowercase.php | 2 +- library/Rules/Nip.php | 2 +- library/Rules/Pesel.php | 2 +- library/Rules/Pis.php | 2 +- library/Rules/Size.php | 4 ++-- library/Rules/StartsWith.php | 4 ++-- library/Rules/Uppercase.php | 2 +- library/Rules/VideoUrl.php | 2 +- library/Rules/Zend.php | 5 +++++ phpstan.neon.dist | 15 +++++++++++++-- tests/integration/assert-with-attributes.phpt | 2 +- tests/library/RuleTestCase.php | 2 +- tests/library/Stubs/ZendValidator.php | 4 +++- tests/unit/Exceptions/CheckExceptionsTest.php | 4 ++++ tests/unit/Rules/AlwaysInvalidTest.php | 2 +- tests/unit/Rules/AlwaysValidTest.php | 2 +- tests/unit/Rules/NoTest.php | 6 +++--- tests/unit/Rules/YesTest.php | 6 +++--- tests/unit/Rules/ZendTest.php | 2 -- 41 files changed, 109 insertions(+), 65 deletions(-) diff --git a/composer.json b/composer.json index 89cd597e..b8cb7d77 100644 --- a/composer.json +++ b/composer.json @@ -23,9 +23,9 @@ "egulias/email-validator": "^2.1", "malukenho/docheader": "^0.1", "mikey179/vfsstream": "^1.6", - "phpstan/phpstan": "^0.11", - "phpstan/phpstan-deprecation-rules": "^0.11.0", - "phpstan/phpstan-phpunit": "^0.11.0", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-deprecation-rules": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", "phpunit/phpunit": "^7.5", "respect/coding-standard": "^2.1", "squizlabs/php_codesniffer": "^3.5", diff --git a/library/Exceptions/NestedValidationException.php b/library/Exceptions/NestedValidationException.php index 25ab54fd..ffcc2a4b 100644 --- a/library/Exceptions/NestedValidationException.php +++ b/library/Exceptions/NestedValidationException.php @@ -22,6 +22,7 @@ use function count; use function current; use function implode; use function is_array; +use function is_string; use function spl_object_hash; use function sprintf; use function str_repeat; @@ -39,6 +40,8 @@ use const PHP_EOL; * @author Henrique Moody * @author Jonathan Stewmon * @author Wojciech Frącz + * + * @implements IteratorAggregate */ class NestedValidationException extends ValidationException implements IteratorAggregate { @@ -215,11 +218,11 @@ class NestedValidationException extends ValidationException implements IteratorA } /** - * @param string[] $templates + * @param string[]|string[][] $templates */ private function renderMessage(ValidationException $exception, array $templates): string { - if (isset($templates[$exception->getId()])) { + if (isset($templates[$exception->getId()]) && is_string($templates[$exception->getId()])) { $exception->updateTemplate($templates[$exception->getId()]); } @@ -227,10 +230,10 @@ class NestedValidationException extends ValidationException implements IteratorA } /** - * @param string[] $templates + * @param string[]|string[][] $templates * @param mixed ...$ids * - * @return string[] + * @return string[]|string[][] */ private function findTemplates(array $templates, ...$ids): array { diff --git a/library/Exceptions/RecursiveExceptionIterator.php b/library/Exceptions/RecursiveExceptionIterator.php index bd4d84c4..5ee53ff5 100644 --- a/library/Exceptions/RecursiveExceptionIterator.php +++ b/library/Exceptions/RecursiveExceptionIterator.php @@ -24,7 +24,7 @@ use UnexpectedValueException; final class RecursiveExceptionIterator implements RecursiveIterator, Countable { /** - * @var ArrayIterator|ValidationException[] + * @var ArrayIterator */ private $exceptions; @@ -67,7 +67,7 @@ final class RecursiveExceptionIterator implements RecursiveIterator, Countable public function key(): int { - return $this->exceptions->key(); + return (int) $this->exceptions->key(); } public function next(): void diff --git a/library/Factory.php b/library/Factory.php index feaccc61..b2e1742f 100644 --- a/library/Factory.php +++ b/library/Factory.php @@ -131,9 +131,11 @@ final class Factory { foreach ($this->rulesNamespaces as $namespace) { try { + /** @var class-string $name */ + $name = $namespace . '\\' . ucfirst($ruleName); /** @var Validatable $rule */ $rule = $this - ->createReflectionClass($namespace . '\\' . ucfirst($ruleName), Validatable::class) + ->createReflectionClass($name, Validatable::class) ->newInstanceArgs($arguments); return $rule; @@ -160,13 +162,16 @@ final class Factory $ruleName = $reflection->getShortName(); $params = ['input' => $input] + $extraParams + $this->extractPropertiesValues($validatable, $reflection); $id = lcfirst($ruleName); - if ($validatable->getName()) { + if ($validatable->getName() !== null) { $id = $params['name'] = $validatable->getName(); } foreach ($this->exceptionsNamespaces as $namespace) { try { + /** @var class-string $exceptionName */ + $exceptionName = $namespace . '\\' . $ruleName . 'Exception'; + return $this->createValidationException( - $namespace . '\\' . $ruleName . 'Exception', + $exceptionName, $id, $input, $params, @@ -183,6 +188,9 @@ final class Factory /** * Creates a reflection based on class name. * + * @param class-string $name + * @param class-string $parentName + * * @throws InvalidClassException * @throws ReflectionException */ @@ -203,6 +211,8 @@ final class Factory /** * Creates a Validation exception. * + * @param class-string $exceptionName + * * @param mixed $input * @param mixed[] $params * diff --git a/library/Helpers/Subdivisions.php b/library/Helpers/Subdivisions.php index 390d7963..95fc8bb7 100644 --- a/library/Helpers/Subdivisions.php +++ b/library/Helpers/Subdivisions.php @@ -34,7 +34,7 @@ final class Subdivisions throw new ComponentException(sprintf('"%s" is not a supported country code', $countryCode)); } - $this->data = (array) json_decode(file_get_contents($filename), true); + $this->data = (array) json_decode((string) file_get_contents($filename), true); } public function getCountry(): string diff --git a/library/Rules/AbstractComposite.php b/library/Rules/AbstractComposite.php index b46dbba8..5ea9c0cb 100644 --- a/library/Rules/AbstractComposite.php +++ b/library/Rules/AbstractComposite.php @@ -67,7 +67,7 @@ abstract class AbstractComposite extends AbstractRule */ public function addRule(Validatable $rule): self { - if ($this->shouldHaveNameOverwritten($rule)) { + if ($this->shouldHaveNameOverwritten($rule) && $this->getName() !== null) { $rule->setName($this->getName()); } diff --git a/library/Rules/AbstractRelated.php b/library/Rules/AbstractRelated.php index ebcf7642..e8046ffc 100644 --- a/library/Rules/AbstractRelated.php +++ b/library/Rules/AbstractRelated.php @@ -63,7 +63,7 @@ abstract class AbstractRelated extends AbstractRule $this->rule = $rule; $this->mandatory = $mandatory; - if ($rule && $rule->getName()) { + if ($rule && $rule->getName() !== null) { $this->setName($rule->getName()); } elseif (is_scalar($reference)) { $this->setName((string) $reference); diff --git a/library/Rules/Callback.php b/library/Rules/Callback.php index 38b34686..066a1139 100644 --- a/library/Rules/Callback.php +++ b/library/Rules/Callback.php @@ -51,12 +51,21 @@ final class Callback extends AbstractRule * {@inheritDoc} */ public function validate($input): bool + { + return (bool) call_user_func_array($this->callback, $this->getArguments($input)); + } + + /** + * @param mixed $input + * @return mixed[] + */ + private function getArguments($input): array { $arguments = [$input]; - if (count($this->arguments) > 0) { - $arguments = array_merge($arguments, $this->arguments); + if (count($this->arguments) === 0) { + return $arguments; } - return (bool) call_user_func_array($this->callback, $arguments); + return array_merge($arguments, $this->arguments); } } diff --git a/library/Rules/Cnh.php b/library/Rules/Cnh.php index fa0681de..faa86cfd 100644 --- a/library/Rules/Cnh.php +++ b/library/Rules/Cnh.php @@ -37,7 +37,7 @@ final class Cnh extends AbstractRule } // Canonicalize input - $input = preg_replace('{\D}', '', (string) $input); + $input = (string) preg_replace('{\D}', '', (string) $input); // Validate length and invalid numbers if (mb_strlen($input) != 11 || ((int) $input === 0)) { diff --git a/library/Rules/Cnpj.php b/library/Rules/Cnpj.php index b60007f5..56ea48c5 100644 --- a/library/Rules/Cnpj.php +++ b/library/Rules/Cnpj.php @@ -80,7 +80,7 @@ final class Cnpj extends AbstractRule return array_map( 'intval', str_split( - preg_replace('/\D/', '', $input) + (string) preg_replace('/\D/', '', $input) ) ); } diff --git a/library/Rules/Contains.php b/library/Rules/Contains.php index 9adc45ef..0e1ec731 100644 --- a/library/Rules/Contains.php +++ b/library/Rules/Contains.php @@ -74,7 +74,7 @@ final class Contains extends AbstractRule return false; } - $encoding = mb_detect_encoding($haystack); + $encoding = (string) mb_detect_encoding($haystack); if ($this->identical) { return mb_strpos($haystack, $needle, 0, $encoding) !== false; } diff --git a/library/Rules/CreditCard.php b/library/Rules/CreditCard.php index 10209e11..8a3d7633 100644 --- a/library/Rules/CreditCard.php +++ b/library/Rules/CreditCard.php @@ -92,7 +92,7 @@ final class CreditCard extends AbstractRule return false; } - $input = preg_replace('/[ .-]/', '', (string) $input); + $input = (string) preg_replace('/[ .-]/', '', (string) $input); if (!(new Luhn())->validate($input)) { return false; } diff --git a/library/Rules/EndsWith.php b/library/Rules/EndsWith.php index 8d17240d..81775bfb 100644 --- a/library/Rules/EndsWith.php +++ b/library/Rules/EndsWith.php @@ -70,7 +70,7 @@ final class EndsWith extends AbstractRule return end($input) == $this->endValue; } - $encoding = mb_detect_encoding($input); + $encoding = (string) mb_detect_encoding($input); $endPosition = mb_strlen($input, $encoding) - mb_strlen($this->endValue, $encoding); return mb_strripos($input, $this->endValue, -1, $encoding) === $endPosition; @@ -85,7 +85,7 @@ final class EndsWith extends AbstractRule return end($input) === $this->endValue; } - $encoding = mb_detect_encoding($input); + $encoding = (string) mb_detect_encoding($input); $endPosition = mb_strlen($input, $encoding) - mb_strlen($this->endValue, $encoding); return mb_strrpos($input, $this->endValue, 0, $encoding) === $endPosition; diff --git a/library/Rules/Factor.php b/library/Rules/Factor.php index 19dda3b6..64ec48af 100644 --- a/library/Rules/Factor.php +++ b/library/Rules/Factor.php @@ -55,7 +55,7 @@ final class Factor extends AbstractRule return false; } - $input = (int) abs($input); + $input = (int) abs((int) $input); $dividend = (int) abs($this->dividend); // The dividend divided by the input must be an integer if input is a diff --git a/library/Rules/Iban.php b/library/Rules/Iban.php index c4e8042c..b71e6518 100644 --- a/library/Rules/Iban.php +++ b/library/Rules/Iban.php @@ -141,7 +141,7 @@ final class Iban extends AbstractRule private function convertToInteger(string $reArrangedIban): string { - return preg_replace_callback( + return (string) preg_replace_callback( '/[A-Z]/', static function (array $match): int { return ord($match[0]) - 55; diff --git a/library/Rules/Image.php b/library/Rules/Image.php index fb737927..ecdbd2cd 100644 --- a/library/Rules/Image.php +++ b/library/Rules/Image.php @@ -61,6 +61,6 @@ final class Image extends AbstractRule return false; } - return mb_strpos($this->fileInfo->file($input), 'image/') === 0; + return mb_strpos((string) $this->fileInfo->file($input), 'image/') === 0; } } diff --git a/library/Rules/Imei.php b/library/Rules/Imei.php index 31922071..b40cd309 100644 --- a/library/Rules/Imei.php +++ b/library/Rules/Imei.php @@ -40,7 +40,7 @@ final class Imei extends AbstractRule return false; } - $numbers = preg_replace('/\D/', '', $input); + $numbers = (string) preg_replace('/\D/', '', (string) $input); if (mb_strlen($numbers) != self::IMEI_SIZE) { return false; } diff --git a/library/Rules/In.php b/library/Rules/In.php index 69f1887b..448ee8af 100644 --- a/library/Rules/In.php +++ b/library/Rules/In.php @@ -29,7 +29,7 @@ use function mb_strpos; final class In extends AbstractRule { /** - * @var mixed[]|string + * @var mixed[]|mixed */ private $haystack; @@ -41,7 +41,7 @@ final class In extends AbstractRule /** * Initializes the rule with the haystack and optionally compareIdentical flag. * - * @param mixed[]|string $haystack + * @param mixed[]|mixed $haystack */ public function __construct($haystack, bool $compareIdentical = false) { @@ -76,7 +76,7 @@ final class In extends AbstractRule $inputString = (string) $input; - return mb_stripos($this->haystack, $inputString, 0, mb_detect_encoding($inputString)) !== false; + return mb_stripos($this->haystack, $inputString, 0, (string) mb_detect_encoding($inputString)) !== false; } /** @@ -94,6 +94,6 @@ final class In extends AbstractRule $inputString = (string) $input; - return mb_strpos($this->haystack, $inputString, 0, mb_detect_encoding($inputString)) !== false; + return mb_strpos($this->haystack, $inputString, 0, (string) mb_detect_encoding($inputString)) !== false; } } diff --git a/library/Rules/Ip.php b/library/Rules/Ip.php index f990e750..ccebc76e 100644 --- a/library/Rules/Ip.php +++ b/library/Rules/Ip.php @@ -125,11 +125,11 @@ final class Ip extends AbstractRule if (mb_strpos($input, '-') !== false) { [$this->startAddress, $this->endAddress] = explode('-', $input); - if (!$this->verifyAddress($this->startAddress)) { + if ($this->startAddress !== null && !$this->verifyAddress($this->startAddress)) { throw new ComponentException('Invalid network range'); } - if (!$this->verifyAddress($this->endAddress)) { + if ($this->endAddress !== null && !$this->verifyAddress($this->endAddress)) { throw new ComponentException('Invalid network range'); } @@ -193,13 +193,15 @@ final class Ip extends AbstractRule { $input = sprintf('%u', ip2long($input)); - return bccomp($input, sprintf('%u', ip2long($this->startAddress))) >= 0 - && bccomp($input, sprintf('%u', ip2long($this->endAddress))) <= 0; + return $this->startAddress !== null + && $this->endAddress !== null + && bccomp($input, sprintf('%u', ip2long($this->startAddress))) >= 0 + && bccomp($input, sprintf('%u', ip2long($this->endAddress))) <= 0; } private function belongsToSubnet(string $input): bool { - if ($this->mask === null) { + if ($this->mask === null || $this->startAddress === null) { return false; } diff --git a/library/Rules/Isbn.php b/library/Rules/Isbn.php index de75cfae..4ad7cb33 100644 --- a/library/Rules/Isbn.php +++ b/library/Rules/Isbn.php @@ -44,6 +44,6 @@ final class Isbn extends AbstractRule return false; } - return preg_match(sprintf('/%s/', implode(self::PIECES)), $input) > 0; + return preg_match(sprintf('/%s/', implode(self::PIECES)), (string) $input) > 0; } } diff --git a/library/Rules/KeyValue.php b/library/Rules/KeyValue.php index 7bdf7071..740c6bd8 100644 --- a/library/Rules/KeyValue.php +++ b/library/Rules/KeyValue.php @@ -121,7 +121,7 @@ final class KeyValue extends AbstractRule try { $rule = Factory::getDefaultInstance()->rule($this->ruleName, [$input[$this->baseKey]]); - $rule->setName($this->comparedKey); + $rule->setName((string) $this->comparedKey); } catch (ComponentException $exception) { throw parent::reportError($input, ['component' => true]); } diff --git a/library/Rules/Length.php b/library/Rules/Length.php index 79b70f92..df0b8fc1 100644 --- a/library/Rules/Length.php +++ b/library/Rules/Length.php @@ -89,7 +89,7 @@ final class Length extends AbstractRule private function extractLength($input): ?int { if (is_string($input)) { - return (int) mb_strlen($input, mb_detect_encoding($input)); + return (int) mb_strlen($input, (string) mb_detect_encoding($input)); } if (is_array($input) || $input instanceof CountableInterface) { diff --git a/library/Rules/Lowercase.php b/library/Rules/Lowercase.php index 1f2871c0..a73231d4 100644 --- a/library/Rules/Lowercase.php +++ b/library/Rules/Lowercase.php @@ -36,6 +36,6 @@ final class Lowercase extends AbstractRule return false; } - return $input === mb_strtolower($input, mb_detect_encoding($input)); + return $input === mb_strtolower($input, (string) mb_detect_encoding($input)); } } diff --git a/library/Rules/Nip.php b/library/Rules/Nip.php index e6520419..9a9463f1 100644 --- a/library/Rules/Nip.php +++ b/library/Rules/Nip.php @@ -42,7 +42,7 @@ final class Nip extends AbstractRule } $weights = [6, 5, 7, 2, 3, 4, 5, 6, 7]; - $digits = array_map('intval', str_split($input)); + $digits = array_map('intval', str_split((string) $input)); $targetControlNumber = $digits[9]; $calculateControlNumber = 0; diff --git a/library/Rules/Pesel.php b/library/Rules/Pesel.php index 59a5137d..9295c2a9 100644 --- a/library/Rules/Pesel.php +++ b/library/Rules/Pesel.php @@ -45,7 +45,7 @@ final class Pesel extends AbstractRule $calculateControlNumber = 0; for ($i = 0; $i < 10; ++$i) { - $calculateControlNumber += $stringInput[$i] * $weights[$i]; + $calculateControlNumber += (int) $stringInput[$i] * $weights[$i]; } $calculateControlNumber = (10 - $calculateControlNumber % 10) % 10; diff --git a/library/Rules/Pis.php b/library/Rules/Pis.php index a7a6c575..65df8fa6 100644 --- a/library/Rules/Pis.php +++ b/library/Rules/Pis.php @@ -36,7 +36,7 @@ final class Pis extends AbstractRule return false; } - $digits = preg_replace('/\D/', '', $input); + $digits = (string) preg_replace('/\D/', '', (string) $input); if (mb_strlen($digits) != 11 || preg_match('/^' . $digits[0] . '{11}$/', $digits)) { return false; } diff --git a/library/Rules/Size.php b/library/Rules/Size.php index 79fb51a5..20f07e09 100644 --- a/library/Rules/Size.php +++ b/library/Rules/Size.php @@ -31,7 +31,7 @@ use function sprintf; final class Size extends AbstractRule { /** - * @var string|null + * @var string|int|null */ private $minSize; @@ -41,7 +41,7 @@ final class Size extends AbstractRule private $minValue; /** - * @var string|null + * @var string|int|null */ private $maxSize; diff --git a/library/Rules/StartsWith.php b/library/Rules/StartsWith.php index 409d3a6a..2ca46c94 100644 --- a/library/Rules/StartsWith.php +++ b/library/Rules/StartsWith.php @@ -68,7 +68,7 @@ final class StartsWith extends AbstractRule return reset($input) == $this->startValue; } - return mb_stripos($input, $this->startValue, 0, mb_detect_encoding($input)) === 0; + return mb_stripos($input, $this->startValue, 0, (string) mb_detect_encoding($input)) === 0; } /** @@ -80,6 +80,6 @@ final class StartsWith extends AbstractRule return reset($input) === $this->startValue; } - return mb_strpos($input, $this->startValue, 0, mb_detect_encoding($input)) === 0; + return mb_strpos($input, $this->startValue, 0, (string) mb_detect_encoding($input)) === 0; } } diff --git a/library/Rules/Uppercase.php b/library/Rules/Uppercase.php index 7d77cbd6..d749f1eb 100644 --- a/library/Rules/Uppercase.php +++ b/library/Rules/Uppercase.php @@ -36,6 +36,6 @@ final class Uppercase extends AbstractRule return false; } - return $input === mb_strtoupper($input, mb_detect_encoding($input)); + return $input === mb_strtoupper($input, (string) mb_detect_encoding($input)); } } diff --git a/library/Rules/VideoUrl.php b/library/Rules/VideoUrl.php index 69d7227f..286c7411 100644 --- a/library/Rules/VideoUrl.php +++ b/library/Rules/VideoUrl.php @@ -32,7 +32,7 @@ use function sprintf; final class VideoUrl extends AbstractRule { /** - * @var string + * @var string|null */ private $service; diff --git a/library/Rules/Zend.php b/library/Rules/Zend.php index de67005d..268ef884 100644 --- a/library/Rules/Zend.php +++ b/library/Rules/Zend.php @@ -21,6 +21,7 @@ use Throwable; use Zend\Validator\ValidatorInterface; use function array_map; +use function class_exists; use function current; use function is_string; use function sprintf; @@ -125,6 +126,10 @@ final class Zend extends AbstractRule $className = stripos($validator, 'Zend') === false ? 'Zend\\Validator\\' . $validator : '\\' . $validator; try { + if (!class_exists($className)) { + throw new ComponentException(sprintf('"%s" is not a valid class name', $className)); + } + $reflection = new ReflectionClass($className); if (!$reflection->isInstantiable()) { throw new ComponentException(sprintf('"%s" is not instantiable', $className)); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 62340e6d..28221563 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -7,9 +7,20 @@ parameters: fileExtensions: - php - phpt + checkGenericClassInNonGenericObjectType: false + checkMissingIterableValueType: false ignoreErrors: - - '/Call to an undefined static method Respect\\Validation\\Validator::iDoNotExistSoIShouldThrowException/' - - '/Parameter #2 $locale of function setlocale expects array|string|null, int given./' + - + message: '/Instanceof between mixed and SimpleXMLElement will always evaluate to false\./' + path: library/Rules/ArrayVal.php + - + message: '/Parameter #1 \$error_handler of function set_error_handler expects \(callable\(int, string, string, int, array\): bool\)\|null, Closure\(\): void given\./' + paths: + - library/Rules/Call.php + - tests/unit/Rules/CallTest.php + - + message: '/Call to an undefined static method Respect\\Validation\\Validator::iDoNotExistSoIShouldThrowException/' + path: tests/unit/ValidatorTest.php level: 7 paths: - library/ diff --git a/tests/integration/assert-with-attributes.phpt b/tests/integration/assert-with-attributes.phpt index 99c0a1a0..5180ddca 100644 --- a/tests/integration/assert-with-attributes.phpt +++ b/tests/integration/assert-with-attributes.phpt @@ -26,7 +26,7 @@ try { 'schema' => 'schema', ], ]; - $object = json_decode(json_encode($array)); + $object = json_decode((string) json_encode($array)); v::create() ->attribute( 'mysql', diff --git a/tests/library/RuleTestCase.php b/tests/library/RuleTestCase.php index 02c64830..02707956 100644 --- a/tests/library/RuleTestCase.php +++ b/tests/library/RuleTestCase.php @@ -64,7 +64,7 @@ abstract class RuleTestCase extends TestCase */ public function getFixtureDirectory(): string { - return realpath(__DIR__ . '/../fixtures'); + return (string) realpath(__DIR__ . '/../fixtures'); } /** diff --git a/tests/library/Stubs/ZendValidator.php b/tests/library/Stubs/ZendValidator.php index 1767f1c6..dbb6a633 100644 --- a/tests/library/Stubs/ZendValidator.php +++ b/tests/library/Stubs/ZendValidator.php @@ -27,8 +27,10 @@ final class ZendValidator implements ValidatorInterface /** * {@inheritDoc} + * + * @return string[] */ - public function getMessages() + public function getMessages(): array { return []; } diff --git a/tests/unit/Exceptions/CheckExceptionsTest.php b/tests/unit/Exceptions/CheckExceptionsTest.php index 5426709a..dc6d7032 100644 --- a/tests/unit/Exceptions/CheckExceptionsTest.php +++ b/tests/unit/Exceptions/CheckExceptionsTest.php @@ -50,6 +50,10 @@ final class CheckExceptionsTest extends TestCase } $className = 'Respect\\Validation\\Rules\\' . $ruleName; + if (!class_exists($className)) { + continue; + } + $reflectionClass = new ReflectionClass($className); if ($reflectionClass->isAbstract() || $reflectionClass->isInterface()) { continue; diff --git a/tests/unit/Rules/AlwaysInvalidTest.php b/tests/unit/Rules/AlwaysInvalidTest.php index e1c6d98c..89aef05d 100644 --- a/tests/unit/Rules/AlwaysInvalidTest.php +++ b/tests/unit/Rules/AlwaysInvalidTest.php @@ -28,7 +28,7 @@ use Respect\Validation\Test\TestCase; final class AlwaysInvalidTest extends TestCase { /** - * {@inheritDoc} + * @return mixed[][] */ public function providerForInvalidInput(): array { diff --git a/tests/unit/Rules/AlwaysValidTest.php b/tests/unit/Rules/AlwaysValidTest.php index b450a5a8..90334c0c 100644 --- a/tests/unit/Rules/AlwaysValidTest.php +++ b/tests/unit/Rules/AlwaysValidTest.php @@ -28,7 +28,7 @@ use Respect\Validation\Test\TestCase; final class AlwaysValidTest extends TestCase { /** - * {@inheritDoc} + * @return mixed[][] */ public function providerForValidInput(): array { diff --git a/tests/unit/Rules/NoTest.php b/tests/unit/Rules/NoTest.php index 56205cf6..021eb483 100644 --- a/tests/unit/Rules/NoTest.php +++ b/tests/unit/Rules/NoTest.php @@ -40,7 +40,7 @@ final class NoTest extends RuleTestCase */ protected function setUp(): void { - $this->locale = setlocale(LC_ALL, 0); + $this->locale = (string) setlocale(LC_ALL, '0'); } /** @@ -117,7 +117,7 @@ final class NoTest extends RuleTestCase { setlocale(LC_ALL, $locale); - if ($locale !== setlocale(LC_ALL, 0)) { + if ($locale !== setlocale(LC_ALL, '0')) { $this->markTestSkipped(sprintf('Could not set locale information to "%s"', $locale)); } @@ -133,7 +133,7 @@ final class NoTest extends RuleTestCase { setlocale(LC_ALL, $locale); - if ($locale !== setlocale(LC_ALL, 0)) { + if ($locale !== setlocale(LC_ALL, '0')) { $this->markTestSkipped(sprintf('Could not set locale information to "%s"', $locale)); } diff --git a/tests/unit/Rules/YesTest.php b/tests/unit/Rules/YesTest.php index 30e43030..045bdef3 100644 --- a/tests/unit/Rules/YesTest.php +++ b/tests/unit/Rules/YesTest.php @@ -44,7 +44,7 @@ final class YesTest extends RuleTestCase */ protected function setUp(): void { - $this->locale = setlocale(LC_ALL, 0); + $this->locale = (string) setlocale(LC_ALL, '0'); } /** @@ -124,7 +124,7 @@ final class YesTest extends RuleTestCase { setlocale(LC_ALL, $locale); - if ($locale !== setlocale(LC_ALL, 0)) { + if ($locale !== setlocale(LC_ALL, '0')) { $this->markTestSkipped(sprintf('Could not set locale information to "%s"', $locale)); } @@ -140,7 +140,7 @@ final class YesTest extends RuleTestCase { setlocale(LC_ALL, $locale); - if ($locale !== setlocale(LC_ALL, 0)) { + if ($locale !== setlocale(LC_ALL, '0')) { $this->markTestSkipped(sprintf('Could not set locale information to "%s"', $locale)); } diff --git a/tests/unit/Rules/ZendTest.php b/tests/unit/Rules/ZendTest.php index cc66a46c..fc7392e4 100644 --- a/tests/unit/Rules/ZendTest.php +++ b/tests/unit/Rules/ZendTest.php @@ -92,8 +92,6 @@ final class ZendTest extends RuleTestCase * @test * * @dataProvider providerForUnbuildableValidator - * - * @param mixed $validator */ public function itShouldThrowAnExceptionWhenValidatorCannotBeCreated(string $validator): void {