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 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
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
53 changes: 50 additions & 3 deletions src/Preg.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,23 @@
final class Preg
{
/**
* @param null|string[] $matches
* @param int-mask<0, 256, 512> $flags
* @todo replace template with variable when https://github.com/phpstan/phpstan/issues/10699 is done
*
* @template TFlags as int-mask<PREG_OFFSET_CAPTURE, PREG_UNMATCHED_AS_NULL>
*
* @param array<array-key, mixed> $matches
* @param TFlags $flags
*
* @param-out (TFlags is PREG_OFFSET_CAPTURE
* ? array<array-key, array{string, 0|positive-int}|array{'', -1}>
* : (TFlags is PREG_UNMATCHED_AS_NULL
* ? array<array-key, string|null>
* : (TFlags is int-mask<PREG_OFFSET_CAPTURE, PREG_UNMATCHED_AS_NULL>&768
* ? array<array-key, array{string, 0|positive-int}|array{null, -1}>
* : array<array-key, string>
* )
* )
* ) $matches
*
* @throws PregException
*/
Expand All @@ -46,7 +61,35 @@ public static function match(string $pattern, string $subject, ?array &$matches
}

/**
* @param null|string[] $matches
* @todo replace template with variable when https://github.com/phpstan/phpstan/issues/10699 is done
*
* @template TFlags as int-mask<PREG_PATTERN_ORDER, PREG_SET_ORDER, PREG_OFFSET_CAPTURE, PREG_UNMATCHED_AS_NULL>
*
* @param array<array-key, mixed> $matches
* @param TFlags $flags
*
* @param-out (TFlags is PREG_PATTERN_ORDER
* ? array<list<string>>
* : (TFlags is PREG_SET_ORDER
* ? list<array<string>>
* : (TFlags is int-mask<PREG_PATTERN_ORDER, PREG_OFFSET_CAPTURE>&(256|257)
* ? array<list<array{string, int}>>
* : (TFlags is int-mask<PREG_SET_ORDER, PREG_OFFSET_CAPTURE>&258
* ? list<array<array{string, int}>>
* : (TFlags is int-mask<PREG_PATTERN_ORDER, PREG_UNMATCHED_AS_NULL>&(512|513)
* ? array<list<?string>>
* : (TFlags is int-mask<PREG_SET_ORDER, PREG_UNMATCHED_AS_NULL>&514
* ? list<array<?string>>
* : (TFlags is int-mask<PREG_SET_ORDER, PREG_OFFSET_CAPTURE, PREG_UNMATCHED_AS_NULL>&770
* ? list<array<array{?string, int}>>
* : array
* )
* )
* )
* )
* )
* )
* ) $matches
*
* @throws PregException
*/
Expand All @@ -68,6 +111,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 +131,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