From 450a834a4604f5f93801c13c1fcbe0c6ca7ea560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Sat, 9 Mar 2024 09:25:05 +0100 Subject: [PATCH] chore: update PHPStan (#7871) --- dev-tools/composer.json | 2 +- dev-tools/composer.lock | 10 +-- dev-tools/phpstan/baseline.php | 65 +++++++++++++++++++ src/Fixer/Naming/NoHomoglyphNamesFixer.php | 2 +- src/Fixer/PhpTag/FullOpeningTagFixer.php | 2 +- .../Phpdoc/PhpdocNoUselessInheritdocFixer.php | 2 +- .../Whitespace/HeredocIndentationFixer.php | 6 +- tests/AutoReview/ProjectCodeTest.php | 2 +- 8 files changed, 78 insertions(+), 13 deletions(-) diff --git a/dev-tools/composer.json b/dev-tools/composer.json index fb0701c6b2d..4fb50bc3cab 100644 --- a/dev-tools/composer.json +++ b/dev-tools/composer.json @@ -7,7 +7,7 @@ "mi-schi/phpmd-extension": "^4.3.0", "phpmd/phpmd": "^2.15.0", "phpstan/extension-installer": "^1.3.1", - "phpstan/phpstan": "^1.10.59", + "phpstan/phpstan": "^1.10.60", "phpstan/phpstan-phpunit": "^1.3.16", "phpstan/phpstan-strict-rules": "^1.5.2" }, diff --git a/dev-tools/composer.lock b/dev-tools/composer.lock index a19df5a96f2..ed7d8645891 100644 --- a/dev-tools/composer.lock +++ b/dev-tools/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "88f0a6e88433b6c987c9e50fe9de98a3", + "content-hash": "34bfda7faca8f509024a89b0043f6f15", "packages": [ { "name": "composer-unused/contracts", @@ -714,16 +714,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.59", + "version": "1.10.60", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "e607609388d3a6d418a50a49f7940e8086798281" + "reference": "95dcea7d6c628a3f2f56d091d8a0219485a86bbe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e607609388d3a6d418a50a49f7940e8086798281", - "reference": "e607609388d3a6d418a50a49f7940e8086798281" + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/95dcea7d6c628a3f2f56d091d8a0219485a86bbe", + "reference": "95dcea7d6c628a3f2f56d091d8a0219485a86bbe" }, "require": { "php": "^7.2|^8.0" diff --git a/dev-tools/phpstan/baseline.php b/dev-tools/phpstan/baseline.php index 560c535dc90..70c7e043abf 100644 --- a/dev-tools/phpstan/baseline.php +++ b/dev-tools/phpstan/baseline.php @@ -6,6 +6,11 @@ 'count' => 1, 'path' => __DIR__ . '/../../src/Console/ConfigurationResolver.php', ]; +$ignoreErrors[] = [ + 'message' => '#^Binary operation "\\+" between int and string results in an error\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/../../src/DocBlock/TypeExpression.php', +]; $ignoreErrors[] = [ 'message' => '#^Foreach overwrites \\$token with its value variable\\.$#', 'count' => 1, @@ -36,11 +41,21 @@ 'count' => 1, 'path' => __DIR__ . '/../../src/Fixer/CastNotation/NoShortBoolCastFixer.php', ]; +$ignoreErrors[] = [ + 'message' => '#^Argument of an invalid type string supplied for foreach, only iterables are supported\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/../../src/Fixer/Import/FullyQualifiedStrictTypesFixer.php', +]; $ignoreErrors[] = [ 'message' => '#^For loop initial assignment overwrites variable \\$index\\.$#', 'count' => 1, 'path' => __DIR__ . '/../../src/Fixer/Import/GlobalNamespaceImportFixer.php', ]; +$ignoreErrors[] = [ + 'message' => '#^Parameter \\#1 \\$array of function array_reverse expects array, string given\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/../../src/Fixer/Import/GlobalNamespaceImportFixer.php', +]; $ignoreErrors[] = [ 'message' => '#^Variable \\$k might not be defined\\.$#', 'count' => 1, @@ -76,11 +91,26 @@ 'count' => 1, 'path' => __DIR__ . '/../../src/Fixer/PhpUnit/PhpUnitConstructFixer.php', ]; +$ignoreErrors[] = [ + 'message' => '#^Argument of an invalid type string supplied for foreach, only iterables are supported\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/../../src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Argument of an invalid type string supplied for foreach, only iterables are supported\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/../../src/Fixer/Phpdoc/PhpdocToCommentFixer.php', +]; $ignoreErrors[] = [ 'message' => '#^Foreach overwrites \\$index with its key variable\\.$#', 'count' => 1, 'path' => __DIR__ . '/../../src/Fixer/Phpdoc/PhpdocTrimConsecutiveBlankLineSeparationFixer.php', ]; +$ignoreErrors[] = [ + 'message' => '#^Argument of an invalid type string supplied for foreach, only iterables are supported\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/../../src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php', +]; $ignoreErrors[] = [ 'message' => '#^Variable \\$end might not be defined\\.$#', 'count' => 2, @@ -96,6 +126,36 @@ 'count' => 1, 'path' => __DIR__ . '/../../src/Fixer/Whitespace/StatementIndentationFixer.php', ]; +$ignoreErrors[] = [ + 'message' => '#^Method PhpCsFixer\\\\Preg\\:\\:match\\(\\) never assigns null to &\\$matches so it can be removed from the by\\-ref type\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/../../src/Preg.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method PhpCsFixer\\\\Preg\\:\\:matchAll\\(\\) never assigns null to &\\$matches so it can be removed from the by\\-ref type\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/../../src/Preg.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method PhpCsFixer\\\\Preg\\:\\:replace\\(\\) never assigns null to &\\$count so it can be removed from the by\\-ref type\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/../../src/Preg.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method PhpCsFixer\\\\Preg\\:\\:replaceCallback\\(\\) never assigns null to &\\$count so it can be removed from the by\\-ref type\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/../../src/Preg.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Parameter &\\$matches by\\-ref type of method PhpCsFixer\\\\Preg\\:\\:match\\(\\) expects array\\\\|null, \\(int is int \\? array\\\\|string\\>\\> \\: \\(int is int \\? array\\ \\: \\(int is int \\? array\\\\> \\: array\\\\)\\)\\) given\\.$#', + 'count' => 2, + 'path' => __DIR__ . '/../../src/Preg.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Parameter &\\$matches by\\-ref type of method PhpCsFixer\\\\Preg\\:\\:matchAll\\(\\) expects array\\\\|null, \\(int is int \\? array\\\\> \\: \\(int is int \\? array\\\\> \\: \\(int is int \\? array\\\\>\\> \\: \\(int is int \\? array\\\\>\\> \\: \\(int is int \\? array\\\\> \\: \\(int is int \\? array\\\\> \\: \\(int is int \\? array\\\\>\\> \\: array\\)\\)\\)\\)\\)\\)\\) given\\.$#', + 'count' => 2, + 'path' => __DIR__ . '/../../src/Preg.php', +]; $ignoreErrors[] = [ 'message' => '#^Parameter \\#1 \\$className \\(string\\) of method PhpCsFixer\\\\StdinFileInfo\\:\\:getFileInfo\\(\\) should be contravariant with parameter \\$class \\(string\\|null\\) of method SplFileInfo\\:\\:getFileInfo\\(\\)$#', 'count' => 1, @@ -106,6 +166,11 @@ 'count' => 1, 'path' => __DIR__ . '/../../src/StdinFileInfo.php', ]; +$ignoreErrors[] = [ + 'message' => '#^PHPDoc tag @var with type array\\ is not subtype of type string\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/../../src/Tokenizer/Analyzer/DataProviderAnalyzer.php', +]; $ignoreErrors[] = [ 'message' => '#^Parameter \\#1 \\$array \\(array\\\\) of method PhpCsFixer\\\\Tokenizer\\\\Tokens\\:\\:fromArray\\(\\) should be contravariant with parameter \\$array \\(array\\\\) of method SplFixedArray\\\\:\\:fromArray\\(\\)$#', 'count' => 1, diff --git a/src/Fixer/Naming/NoHomoglyphNamesFixer.php b/src/Fixer/Naming/NoHomoglyphNamesFixer.php index 55c5ffda6f7..ff91d5c1333 100644 --- a/src/Fixer/Naming/NoHomoglyphNamesFixer.php +++ b/src/Fixer/Naming/NoHomoglyphNamesFixer.php @@ -222,7 +222,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $replaced = Preg::replaceCallback('/[^[:ascii:]]/u', static fn (array $matches): string => self::$replacements[$matches[0]] ?? $matches[0], $token->getContent(), -1, $count); - if ($count) { + if ($count > 0) { $tokens->offsetSet($index, new Token([$token->getId(), $replaced])); } } diff --git a/src/Fixer/PhpTag/FullOpeningTagFixer.php b/src/Fixer/PhpTag/FullOpeningTagFixer.php index 61186ccd295..bf6c1313ab1 100644 --- a/src/Fixer/PhpTag/FullOpeningTagFixer.php +++ b/src/Fixer/PhpTag/FullOpeningTagFixer.php @@ -62,7 +62,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // replace all 0) { $tokens[$tokenIndex] = new Token([T_DOC_COMMENT, $content]); } } diff --git a/src/Fixer/Whitespace/HeredocIndentationFixer.php b/src/Fixer/Whitespace/HeredocIndentationFixer.php index e40b64de5a1..4babba28c24 100644 --- a/src/Fixer/Whitespace/HeredocIndentationFixer.php +++ b/src/Fixer/Whitespace/HeredocIndentationFixer.php @@ -140,7 +140,7 @@ private function fixIndentation(Tokens $tokens, int $start, int $end): void $content = Preg::replace('/(?<=\v)(?!'.$currentIndent.')\h+/', '', $content); } - $regexEnd = $last && !$currentIndent ? '(?!\v|$)' : '(?!\v)'; + $regexEnd = $last && '' === $currentIndent ? '(?!\v|$)' : '(?!\v)'; $content = Preg::replace('/(?<=\v)'.$currentIndent.$regexEnd.'/', $indent, $content); $tokens[$index] = new Token([$tokens[$index]->getId(), $content]); @@ -156,9 +156,9 @@ private function fixIndentation(Tokens $tokens, int $start, int $end): void $content = $tokens[$index]->getContent(); - if (!\in_array($content[0], ["\r", "\n"], true) && (!$currentIndent || str_starts_with($content, $currentIndent))) { + if (!\in_array($content[0], ["\r", "\n"], true) && ('' === $currentIndent || str_starts_with($content, $currentIndent))) { $content = $indent.substr($content, $currentIndentLength); - } elseif ($currentIndent) { + } elseif ('' !== $currentIndent) { $content = Preg::replace('/^(?!'.$currentIndent.')\h+/', '', $content); } diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index cb95033fcef..668bf31c41a 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -305,7 +305,7 @@ public function testThatTestClassCoversAreCorrect(string $testClassName): void $doc = $reflectionClass->getDocComment(); self::assertNotFalse($doc); - if (Preg::match('/@coversNothing/', $doc, $matches)) { + if (Preg::match('/@coversNothing/', $doc)) { return; }