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: fix PHPStan 1.10.60 issues #7873

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
65 changes: 0 additions & 65 deletions dev-tools/phpstan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
'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 @@ -41,21 +36,11 @@
'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 @@ -91,26 +76,11 @@
'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 @@ -126,36 +96,6 @@
'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 @@ -166,11 +106,6 @@
'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
50 changes: 47 additions & 3 deletions src/Preg.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,21 @@
final class Preg
{
/**
* @param null|string[] $matches
* @param int-mask<0, 256, 512> $flags
* @template TFlags as int-mask<0, 256, 512>
*
* @param null|mixed[] $matches
* @param TFlags $flags
kubawerlos marked this conversation as resolved.
Show resolved Hide resolved
*
* @param-out (TFlags is 256
* ? array<array-key, array{string, 0|positive-int}|array{'', -1}>
* : (TFlags is 512
* ? array<array-key, string|null>
* : (TFlags is 768
kubawerlos marked this conversation as resolved.
Show resolved Hide resolved
* ? array<array-key, array{string, 0|positive-int}|array{null, -1}>
kubawerlos marked this conversation as resolved.
Show resolved Hide resolved
* : array<array-key, string>
* )
* )
* ) $matches
*
* @throws PregException
*/
Expand All @@ -46,7 +59,34 @@ public static function match(string $pattern, string $subject, ?array &$matches
}

/**
* @param null|string[] $matches
* @template TFlags as int
kubawerlos marked this conversation as resolved.
Show resolved Hide resolved
*
* @param null|mixed[][] $matches
* @param TFlags $flags
*
* @param-out (
* TFlags is 1
* ? array<list<string>>
* : (TFlags is 2
* ? list<array<string>>
* : (TFlags is 256|257
* ? array<list<array{string, int}>>
* : (TFlags is 258
* ? list<array<array{string, int}>>
* : (TFlags is 512|513
* ? array<list<?string>>
* : (TFlags is 514
* ? list<array<?string>>
* : (TFlags is 770
* ? list<array<array{?string, int}>>
* : array
* )
* )
* )
* )
* )
* )
* ) $matches
*
* @throws PregException
*/
Expand All @@ -68,6 +108,8 @@ public static function matchAll(string $pattern, string $subject, ?array &$match
/**
* @param string|string[] $subject
*
* @param-out int $count
*
* @throws PregException
*/
public static function replace(string $pattern, string $replacement, $subject, int $limit = -1, ?int &$count = null): string
Expand All @@ -86,6 +128,8 @@ public static function replace(string $pattern, string $replacement, $subject, i
}

/**
* @param-out int $count
*
* @throws PregException
*/
public static function replaceCallback(string $pattern, callable $callback, string $subject, int $limit = -1, ?int &$count = null): string
Expand Down
5 changes: 1 addition & 4 deletions src/Tokenizer/Analyzer/DataProviderAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ public function getDataProviders(Tokens $tokens, int $startIndex, int $endIndex)

Preg::matchAll('/@dataProvider\h+(('.self::REGEX_CLASS.'::)?'.TypeExpression::REGEX_IDENTIFIER.')/', $tokens[$docCommentIndex]->getContent(), $matches);

/** @var list<string> $matches */
$matches = $matches[1];

foreach ($matches as $dataProviderName) {
foreach ($matches[1] as $dataProviderName) {
$dataProviders[$dataProviderName][] = $docCommentIndex;
}
}
Expand Down