diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 6d9f502..cfcf0af 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -17,7 +17,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] os: ['ubuntu-latest'] steps: @@ -31,7 +31,9 @@ jobs: tools: phpcs - name: Setup dependencies - run: composer require -n --no-progress overtrue/phplint + run: | + composer require -n --no-progress overtrue/phplint phpstan/phpstan + sudo cp -R vendor /usr/share/icinga-php - name: PHP Lint if: ${{ ! cancelled() }} @@ -43,7 +45,7 @@ jobs: - name: PHPStan if: ${{ ! cancelled() }} - uses: php-actions/phpstan@v3 + run: ./vendor/bin/phpstan analyse test: name: Unit tests with php ${{ matrix.php }} on ${{ matrix.os }} @@ -55,7 +57,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] os: ['ubuntu-latest'] steps: diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon deleted file mode 100644 index c8aa3b3..0000000 --- a/phpstan-baseline.neon +++ /dev/null @@ -1,96 +0,0 @@ -parameters: - ignoreErrors: - - - message: "#^Method ipl\\\\Validator\\\\BetweenValidator\\:\\:__construct\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" - count: 1 - path: src/BetweenValidator.php - - - - message: "#^Method ipl\\\\Validator\\\\DeferredInArrayValidator\\:\\:__construct\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" - count: 1 - path: src/DeferredInArrayValidator.php - - - - message: "#^Method ipl\\\\Validator\\\\DeferredInArrayValidator\\:\\:getHaystack\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/DeferredInArrayValidator.php - - - - message: "#^Method ipl\\\\Validator\\\\EmailAddressValidator\\:\\:__construct\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" - count: 1 - path: src/EmailAddressValidator.php - - - - message: "#^Method ipl\\\\Validator\\\\FileValidator\\:\\:__construct\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" - count: 1 - path: src/FileValidator.php - - - - message: "#^Method ipl\\\\Validator\\\\GreaterThanValidator\\:\\:__construct\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" - count: 1 - path: src/GreaterThanValidator.php - - - - message: "#^Method ipl\\\\Validator\\\\InArrayValidator\\:\\:__construct\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" - count: 1 - path: src/InArrayValidator.php - - - - message: "#^Method ipl\\\\Validator\\\\InArrayValidator\\:\\:findInvalid\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#" - count: 1 - path: src/InArrayValidator.php - - - - message: "#^Method ipl\\\\Validator\\\\InArrayValidator\\:\\:findInvalid\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/InArrayValidator.php - - - - message: "#^Method ipl\\\\Validator\\\\InArrayValidator\\:\\:getHaystack\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/InArrayValidator.php - - - - message: "#^Method ipl\\\\Validator\\\\InArrayValidator\\:\\:setHaystack\\(\\) has parameter \\$haystack with no value type specified in iterable type array\\.$#" - count: 1 - path: src/InArrayValidator.php - - - - message: "#^Property ipl\\\\Validator\\\\InArrayValidator\\:\\:\\$haystack type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/InArrayValidator.php - - - - message: "#^Method ipl\\\\Validator\\\\LessThanValidator\\:\\:__construct\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" - count: 1 - path: src/LessThanValidator.php - - - - message: "#^Method ipl\\\\Validator\\\\StringLengthValidator\\:\\:__construct\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" - count: 1 - path: src/StringLengthValidator.php - - - - message: "#^Class ipl\\\\Validator\\\\ValidatorChain implements generic interface IteratorAggregate but does not specify its types\\: TKey, TValue$#" - count: 1 - path: src/ValidatorChain.php - - - - message: "#^Method ipl\\\\Validator\\\\ValidatorChain\\:\\:addValidators\\(\\) has parameter \\$validators with no value type specified in iterable type iterable\\.$#" - count: 1 - path: src/ValidatorChain.php - - - - message: "#^Method ipl\\\\Validator\\\\ValidatorChain\\:\\:getValidatorsThatBreakTheChain\\(\\) return type with generic class SplObjectStorage does not specify its types\\: TObject, TData$#" - count: 1 - path: src/ValidatorChain.php - - - - message: "#^Method ipl\\\\Validator\\\\ValidatorChain\\:\\:toArray\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/ValidatorChain.php - - - - message: "#^Property ipl\\\\Validator\\\\ValidatorChain\\:\\:\\$validatorsThatBreakTheChain with generic class SplObjectStorage does not specify its types\\: TObject, TData$#" - count: 1 - path: src/ValidatorChain.php diff --git a/phpstan.neon b/phpstan.neon index b0ed57d..303e5ef 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,3 @@ -includes: - - phpstan-baseline.neon - parameters: level: max @@ -12,7 +9,7 @@ parameters: - src scanDirectories: - - vendor + - /usr/share/icinga-php ignoreErrors: - diff --git a/src/BetweenValidator.php b/src/BetweenValidator.php index 90a6146..c8dc026 100644 --- a/src/BetweenValidator.php +++ b/src/BetweenValidator.php @@ -40,7 +40,7 @@ class BetweenValidator extends BaseValidator * * - inclusive: (bool) Whether inclusive border values, default true * - * @param array $options + * @param array{min: int|float, max: int|float, inclusive?: bool} $options * * @throws Exception When required option is missing */ diff --git a/src/DeferredInArrayValidator.php b/src/DeferredInArrayValidator.php index 55b9b83..fa0ba5d 100644 --- a/src/DeferredInArrayValidator.php +++ b/src/DeferredInArrayValidator.php @@ -15,7 +15,7 @@ class DeferredInArrayValidator extends InArrayValidator * * **Required parameter:** * - * - `callback`: (`callable`) The callback to create haystack + * - `callback`: (`callable`) The callback to create the haystack * * **Optional parameter:** * @@ -23,8 +23,8 @@ class DeferredInArrayValidator extends InArrayValidator * * * `strict`: (`bool`) Whether the types of the needle in the haystack should also match, default `false` * - * @param callable $callback Validation callback - * @param array $options + * @param callable $callback The callback to create the haystack + * @param array{haystack?: mixed[], strict?: bool} $options */ public function __construct(callable $callback, array $options = []) { diff --git a/src/EmailAddressValidator.php b/src/EmailAddressValidator.php index f98e18e..e9dc2a7 100644 --- a/src/EmailAddressValidator.php +++ b/src/EmailAddressValidator.php @@ -40,7 +40,7 @@ class EmailAddressValidator extends BaseValidator * 'mx' => If an MX check should be enabled, boolean * 'deep' => If a deep MX check should be enabled, boolean * - * @param array $options + * @param array{max?: bool, deep?: bool} $options * * @throws Exception */ diff --git a/src/FileValidator.php b/src/FileValidator.php index 4ba2888..bc435cc 100644 --- a/src/FileValidator.php +++ b/src/FileValidator.php @@ -34,6 +34,8 @@ class FileValidator extends BaseValidator * - maxSize: (int) Maximum allowed file size, by default no limit * - maxFileNameLength: (int) Maximum allowed file name length, by default no limit * - mimeType: (array) Allowed mime types, by default no restriction + * + * @param array{minSize?: int, maxSize?: int, maxFileNameLength?: int, mimeType?: string[]} $options */ public function __construct(array $options = []) { @@ -243,7 +245,7 @@ private function validateFile(UploadedFileInterface $file): bool $this->translate('File %s is of type %s. Only %s allowed.'), $file->getClientFilename(), $file->getClientMediaType(), - implode(', ', $this->allowedMimeTypes) + implode(', ', $this->allowedMimeTypes ?? []) )); $isValid = false; diff --git a/src/GreaterThanValidator.php b/src/GreaterThanValidator.php index 58166c6..177fa42 100644 --- a/src/GreaterThanValidator.php +++ b/src/GreaterThanValidator.php @@ -19,6 +19,8 @@ class GreaterThanValidator extends BaseValidator * * Optional options: * - min: (int|float) Comparison value for greater than, default 0 + * + * @param array{min?: int|float} $options */ public function __construct(array $options = []) { diff --git a/src/InArrayValidator.php b/src/InArrayValidator.php index 32868d8..f3e67e7 100644 --- a/src/InArrayValidator.php +++ b/src/InArrayValidator.php @@ -11,7 +11,7 @@ class InArrayValidator extends BaseValidator { use Translation; - /** @var ?array The array */ + /** @var ?mixed[] The array */ protected $haystack; /** @var bool Whether the types of the needle in the haystack should also match */ @@ -25,7 +25,7 @@ class InArrayValidator extends BaseValidator * * `haystack`: (`array`) The array * * `strict`: (`bool`) Whether the types of the needle in the haystack should also match, default `false` * - * @param array $options + * @param array{haystack?: mixed[], strict?: bool} $options */ public function __construct(array $options = []) { @@ -39,7 +39,7 @@ public function __construct(array $options = []) /** * Get the haystack * - * @return array + * @return mixed[] */ public function getHaystack(): array { @@ -49,7 +49,7 @@ public function getHaystack(): array /** * Set the haystack * - * @param array $haystack + * @param mixed[] $haystack * * @return $this */ @@ -110,9 +110,9 @@ public function isValid($value): bool /** * Get the values from the specified array that are not present in the haystack * - * @param array $values + * @param mixed[] $values * - * @return array Values not found in the haystack + * @return mixed[] Values not found in the haystack */ protected function findInvalid(array $values = []): array { diff --git a/src/LessThanValidator.php b/src/LessThanValidator.php index 50b566f..db80e1a 100644 --- a/src/LessThanValidator.php +++ b/src/LessThanValidator.php @@ -19,6 +19,8 @@ class LessThanValidator extends BaseValidator * * Optional options: * - max: (int|float) Comparison value for less than, default 0 + * + * @param array{max?: int|float} $options */ public function __construct(array $options = []) { diff --git a/src/StringLengthValidator.php b/src/StringLengthValidator.php index 0322c1c..d4dd44b 100644 --- a/src/StringLengthValidator.php +++ b/src/StringLengthValidator.php @@ -26,9 +26,11 @@ class StringLengthValidator extends BaseValidator * Create a new StringLengthValidator * * Optional options: - * - min: (scalar) Minimum required string length, default 0 - * - max: (scalar) Maximum required string length, default null - * - encoding: (string) Encoding type, default null + * - min: (int) Minimum required string length, default 0 + * - max: (int) Maximum required string length, default none + * - encoding: (string) Encoding type, default none + * + * @param array{min?: int, max?: int, encoding?: string} $options */ public function __construct(array $options = []) { diff --git a/src/ValidatorChain.php b/src/ValidatorChain.php index 92249c2..8f0b9f3 100644 --- a/src/ValidatorChain.php +++ b/src/ValidatorChain.php @@ -15,6 +15,7 @@ use function ipl\Stdlib\get_php_type; +/** @implements IteratorAggregate */ class ValidatorChain implements Countable, IteratorAggregate, Validator { use Messages; @@ -23,10 +24,10 @@ class ValidatorChain implements Countable, IteratorAggregate, Validator /** Default priority at which validators are added */ const DEFAULT_PRIORITY = 1; - /** @var PriorityQueue Validator chain */ + /** @var PriorityQueue Validator chain */ protected $validators; - /** @var SplObjectStorage Validators that break the chain on failure */ + /** @var SplObjectStorage Validators that break the chain on failure */ protected $validatorsThatBreakTheChain; /** @@ -43,7 +44,7 @@ public function __construct() /** * Get the validators that break the chain * - * @return SplObjectStorage + * @return SplObjectStorage */ public function getValidatorsThatBreakTheChain() { @@ -76,7 +77,7 @@ public function add(Validator $validator, $breakChainOnFailure = false, $priorit /** * Add the validators from the given validator specification to the chain * - * @param iterable $validators + * @param static|Traversable $validators * * @return $this * @@ -240,11 +241,14 @@ public function __clone() /** * Export the chain as array * - * @return array + * @return Validator[] */ public function toArray() { - return array_values(iterator_to_array($this)); + /** @var Validator[] $validators */ + $validators = iterator_to_array($this); + + return array_values($validators); } public function count(): int @@ -255,7 +259,7 @@ public function count(): int /** * Get an iterator for traversing the validators * - * @return Validator[]|PriorityQueue + * @return PriorityQueue */ public function getIterator(): Traversable {