Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update PHPStan #7871

Merged
merged 2 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev-tools/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
10 changes: 5 additions & 5 deletions dev-tools/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions dev-tools/phpstan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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\\<string\\>\\|null, \\(int is int \\? array\\<array\\<int, int\\<\\-1, max\\>\\|string\\>\\> \\: \\(int is int \\? array\\<string\\|null\\> \\: \\(int is int \\? array\\<array\\<int, int\\|string\\|null\\>\\> \\: array\\<string\\>\\)\\)\\) given\\.$#',
'count' => 2,
'path' => __DIR__ . '/../../src/Preg.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter &\\$matches by\\-ref type of method PhpCsFixer\\\\Preg\\:\\:matchAll\\(\\) expects array\\<string\\>\\|null, \\(int is int \\? array\\<array\\<int, string\\>\\> \\: \\(int is int \\? array\\<int, array\\<string\\>\\> \\: \\(int is int \\? array\\<array\\<int, array\\<int, int\\|string\\>\\>\\> \\: \\(int is int \\? array\\<int, array\\<array\\<int, int\\|string\\>\\>\\> \\: \\(int is int \\? array\\<array\\<int, string\\|null\\>\\> \\: \\(int is int \\? array\\<int, array\\<string\\|null\\>\\> \\: \\(int is int \\? array\\<int, array\\<array\\<int, int\\|string\\|null\\>\\>\\> \\: 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,
Expand All @@ -106,6 +166,11 @@
'count' => 1,
'path' => __DIR__ . '/../../src/StdinFileInfo.php',
];
$ignoreErrors[] = [
'message' => '#^PHPDoc tag @var with type array\\<int, string\\> is not subtype of type string\\.$#',
'count' => 1,
'path' => __DIR__ . '/../../src/Tokenizer/Analyzer/DataProviderAnalyzer.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$array \\(array\\<int, PhpCsFixer\\\\Tokenizer\\\\Token\\>\\) of method PhpCsFixer\\\\Tokenizer\\\\Tokens\\:\\:fromArray\\(\\) should be contravariant with parameter \\$array \\(array\\<int, mixed\\>\\) of method SplFixedArray\\<PhpCsFixer\\\\Tokenizer\\\\Token\\>\\:\\:fromArray\\(\\)$#',
'count' => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Naming/NoHomoglyphNamesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/PhpTag/FullOpeningTagFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
// replace all <? with <?php to replace all short open tags even without short_open_tag option enabled
$newContent = Preg::replace('/<\?(?:phP|pHp|pHP|Php|PhP|PHp|PHP)?(\s|$)/', '<?php$1', $content, -1, $count);

if (!$count) {
if (0 === $count) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private function fixToken(Tokens $tokens, int $tokenIndex): void
$count
);

if ($count) {
if ($count > 0) {
$tokens[$tokenIndex] = new Token([T_DOC_COMMENT, $content]);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Fixer/Whitespace/HeredocIndentationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/AutoReview/ProjectCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down