From 99696a3e775f49d371dc50bd9d23108e7711a1a1 Mon Sep 17 00:00:00 2001 From: paranoiq Date: Fri, 24 Feb 2023 17:39:27 +0100 Subject: [PATCH] Updated PHPStan; min PHP version is 7.4 --- build/PHPStan/phpstan.neon | 8 ++++++++ composer.json | 18 ++++++------------ src/Dom/NodeList.php | 4 +++- src/Io/Filesystem/DirectoryIterator.php | 2 ++ .../Filesystem/RecursiveDirectoryIterator.php | 6 ++++-- src/Mapping/MappingIterator.php | 2 ++ src/common/Str.php | 3 +-- tests/src/Http/responder.php | 2 +- tests/src/common/Re.phpt | 5 +++++ 9 files changed, 32 insertions(+), 18 deletions(-) diff --git a/build/PHPStan/phpstan.neon b/build/PHPStan/phpstan.neon index e4c342d2..000fbf7a 100644 --- a/build/PHPStan/phpstan.neon +++ b/build/PHPStan/phpstan.neon @@ -38,6 +38,14 @@ parameters: - message: '~Negated boolean expression is always true~' path: "../../src/common/lists/ImmutableArray.php" + - + message: '~Strict comparison using === between \*NEVER\* and 0 will always evaluate to false~' + path: "../../tests/src/Http/responder.php" + + # Re flags & WTFs + - '~Parameter #4 \$flags of function preg_match expects TFlags of 0|256|512|768, int given.~' + - '~Method Dogma\\Re::match\(\) should return array\|null but returns array\|string\|null>.~' + - '~Method Dogma\\Re::submatch\(\) should return string\|null but returns array\|string\|null.~' # interface - '~^PHPDoc tag @return with type Dogma\\Language\\Locale\\LocaleCollationOption is not subtype of native type Dogma\\Enum\\StringEnum~' diff --git a/composer.json b/composer.json index 11fb371a..1a47cfd1 100644 --- a/composer.json +++ b/composer.json @@ -11,14 +11,14 @@ } ], "require": { - "php": "^7.2|^8.0", + "php": "^7.4|^8.0", "ext-calendar":"*", "nette/http": "~2.4|~3.0", "nette/utils": "~2.4|~3.0|~4.0" }, "require-dev": { "dogma/dogma-dev": "0.1.29", - "phpstan/phpstan": "1.8.2" + "phpstan/phpstan": "1.10.2" }, "suggest": { "ext-dom": "for Dom (basic functionality)", @@ -76,9 +76,7 @@ "php82 vendor/nette/tester/src/tester tests -c tests --colors 1", "php81 vendor/nette/tester/src/tester tests -c tests --colors 1", "php80 vendor/nette/tester/src/tester tests -c tests --colors 1", - "php74 vendor/nette/tester/src/tester tests -c tests --colors 1", - "php73 vendor/nette/tester/src/tester tests -c tests --colors 1", - "php72 vendor/nette/tester/src/tester tests -c tests --colors 1" + "php74 vendor/nette/tester/src/tester tests -c tests --colors 1" ], "tests:coverage": "php vendor/nette/tester/src/tester tests -c tests --colors 1 -p phpdbg --coverage tests/coverage.html --coverage-src src", @@ -87,9 +85,7 @@ "php82 vendor/phpstan/phpstan/phpstan analyse --memory-limit 256M -c build/PHPStan/phpstan.neon", "php81 vendor/phpstan/phpstan/phpstan analyse --memory-limit 256M -c build/PHPStan/phpstan.neon", "php80 vendor/phpstan/phpstan/phpstan analyse --memory-limit 256M -c build/PHPStan/phpstan.neon", - "php74 vendor/phpstan/phpstan/phpstan analyse --memory-limit 256M -c build/PHPStan/phpstan.neon", - "php73 vendor/phpstan/phpstan/phpstan analyse --memory-limit 256M -c build/PHPStan/phpstan.neon", - "php72 vendor/phpstan/phpstan/phpstan analyse --memory-limit 256M -c build/PHPStan/phpstan.neon" + "php74 vendor/phpstan/phpstan/phpstan analyse --memory-limit 256M -c build/PHPStan/phpstan.neon" ], "lint:php": "php vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests", @@ -97,9 +93,7 @@ "php82 vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests", "php81 vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests", "php80 vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests", - "php74 vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests", - "php73 vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests", - "php72 vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests" + "php74 vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests" ], "phpcs:all": [ @@ -156,7 +150,7 @@ "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": false, - "sllh/composer-versions-check": true + "sllh/composer-versions-check": false } } } diff --git a/src/Dom/NodeList.php b/src/Dom/NodeList.php index 1d8ca913..757f4012 100644 --- a/src/Dom/NodeList.php +++ b/src/Dom/NodeList.php @@ -15,9 +15,10 @@ use DOMNode; use DOMNodeList; use Iterator; +use ReturnTypeWillChange; /** - * @implements Iterator + * @implements Iterator */ class NodeList implements Countable, Iterator { @@ -65,6 +66,7 @@ public function count(): int /** * @return Element|DOMNode */ + #[ReturnTypeWillChange] public function current() { /** @var DOMNode $item */ diff --git a/src/Io/Filesystem/DirectoryIterator.php b/src/Io/Filesystem/DirectoryIterator.php index 6a111d31..b00941cb 100644 --- a/src/Io/Filesystem/DirectoryIterator.php +++ b/src/Io/Filesystem/DirectoryIterator.php @@ -10,6 +10,7 @@ namespace Dogma\Io\Filesystem; use FilesystemIterator; +use ReturnTypeWillChange; use UnexpectedValueException; class DirectoryIterator extends FilesystemIterator @@ -53,6 +54,7 @@ public function setFlags($flags = null): void /** * @return FileInfo|mixed */ + #[ReturnTypeWillChange] public function current() { if (!($this->flags & FilesystemIterator::CURRENT_AS_PATHNAME) && !($this->flags & FilesystemIterator::CURRENT_AS_SELF)) { diff --git a/src/Io/Filesystem/RecursiveDirectoryIterator.php b/src/Io/Filesystem/RecursiveDirectoryIterator.php index 4292f4bf..e5dd3430 100644 --- a/src/Io/Filesystem/RecursiveDirectoryIterator.php +++ b/src/Io/Filesystem/RecursiveDirectoryIterator.php @@ -11,6 +11,7 @@ use FilesystemIterator; use RecursiveDirectoryIterator as PhpRecursiveDirectoryIterator; +use ReturnTypeWillChange; use UnexpectedValueException; class RecursiveDirectoryIterator extends PhpRecursiveDirectoryIterator @@ -44,7 +45,7 @@ public function __construct(string $path, ?int $flags = null) public function setFlags($flags = null): void { $this->flags = $flags; - if ($flags & FilesystemIterator::CURRENT_AS_FILEINFO) { + if (!($flags & FilesystemIterator::CURRENT_AS_PATHNAME) && !($flags & FilesystemIterator::CURRENT_AS_SELF)) { parent::setFlags($flags | FilesystemIterator::CURRENT_AS_PATHNAME); } else { parent::setFlags($flags); @@ -54,9 +55,10 @@ public function setFlags($flags = null): void /** * @return FileInfo|mixed */ + #[ReturnTypeWillChange] public function current() { - if ($this->flags & FilesystemIterator::CURRENT_AS_FILEINFO) { + if (!($this->flags & FilesystemIterator::CURRENT_AS_PATHNAME) && !($this->flags & FilesystemIterator::CURRENT_AS_SELF)) { /** @var string $path */ $path = parent::current(); diff --git a/src/Mapping/MappingIterator.php b/src/Mapping/MappingIterator.php index a185bb2a..25ea181d 100644 --- a/src/Mapping/MappingIterator.php +++ b/src/Mapping/MappingIterator.php @@ -15,6 +15,7 @@ use Dogma\Type; use Iterator; use IteratorAggregate; +use ReturnTypeWillChange; use function is_array; /** @@ -77,6 +78,7 @@ public function valid(): bool /** * @return mixed|null */ + #[ReturnTypeWillChange] public function current() { if ($this->reverse) { diff --git a/src/common/Str.php b/src/common/Str.php index 99951b74..b986e01c 100644 --- a/src/common/Str.php +++ b/src/common/Str.php @@ -14,14 +14,12 @@ use Collator as PhpCollator; use Dogma\Language\Collator; -use Dogma\Language\Encoding; use Dogma\Language\Locale\Locale; use Dogma\Language\Transliterator; use Dogma\Language\UnicodeCharacterCategory; use Error; use Nette\Utils\Strings; use UConverter; -use const MB_CASE_TITLE; use function array_keys; use function array_pop; use function array_shift; @@ -53,6 +51,7 @@ use function strrpos; use function strtolower; use function substr; +use const MB_CASE_TITLE; /** * UTF-8 strings manipulation diff --git a/tests/src/Http/responder.php b/tests/src/Http/responder.php index 4d8a6399..1d88cfbf 100644 --- a/tests/src/Http/responder.php +++ b/tests/src/Http/responder.php @@ -143,7 +143,7 @@ if ($request['time']) { $chunkSize = (int) ($request['size'] / $request['time']); for ($n = 0; $n < $request['size']; $n++) { - if ($n % $chunkSize === 0) { + if (($n % $chunkSize) === 0) { sleep(1); } if ($n % 100 === 0) { diff --git a/tests/src/common/Re.phpt b/tests/src/common/Re.phpt index 4bc5d54b..18999381 100644 --- a/tests/src/common/Re.phpt +++ b/tests/src/common/Re.phpt @@ -12,3 +12,8 @@ pos: Assert::same(Re::pos('abc@def', '~#~'), null); Assert::same(Re::pos('abc@def', '~@~'), 3); Assert::same(Re::pos('abc@def', '~@([def])~'), 3); + +submatch: +Assert::same(Re::submatch('abc@def', '~(abc)~'), 'abc'); +Assert::same(Re::submatch('abc@def', '~(def)~'), 'def'); +Assert::same(Re::submatch('abc@def', '~(foo)~'), null);