From 450d8cb7b81ea01d59b06c3235bfbf42dd8ab616 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Thu, 25 Jan 2024 02:29:35 +0100 Subject: [PATCH 1/4] phpstan: Streamline vendor file location with local dev-env phpstan is not run with an action anymore, as the action runs it its own docker container and hence has no access to files outside the repository root. A side-effect of this is, that phpstan now **really** runs with the php version set up by the matrix. --- .github/workflows/php.yml | 6 ++++-- phpstan.neon | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 6d9f502..122a1f8 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -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 }} diff --git a/phpstan.neon b/phpstan.neon index b0ed57d..b95427a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -12,7 +12,7 @@ parameters: - src scanDirectories: - - vendor + - /usr/share/icinga-php ignoreErrors: - From 5781506a5c87ce723d666f7697bac6c3413b673f Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Thu, 25 Jan 2024 02:44:16 +0100 Subject: [PATCH 2/4] GithubActions: Add php 8.3 --- .github/workflows/php.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 122a1f8..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: @@ -57,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: From be23fe66b03044955fb5a685b2c24f8d8683ea03 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 12 Feb 2024 16:23:15 +0100 Subject: [PATCH 3/4] Improve several type hints --- src/BetweenValidator.php | 2 +- src/DeferredInArrayValidator.php | 6 +++--- src/EmailAddressValidator.php | 2 +- src/FileValidator.php | 4 +++- src/GreaterThanValidator.php | 2 ++ src/InArrayValidator.php | 12 ++++++------ src/LessThanValidator.php | 2 ++ src/StringLengthValidator.php | 8 +++++--- src/ValidatorChain.php | 18 +++++++++++------- 9 files changed, 34 insertions(+), 22 deletions(-) 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 { From cfe15ead448038dd793de71672a77e796bea3151 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 12 Feb 2024 16:27:30 +0100 Subject: [PATCH 4/4] phpstan: Drop baseline Unbelievable, right? --- phpstan-baseline.neon | 96 ------------------------------------------- phpstan.neon | 3 -- 2 files changed, 99 deletions(-) delete mode 100644 phpstan-baseline.neon 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 b95427a..303e5ef 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,3 @@ -includes: - - phpstan-baseline.neon - parameters: level: max