Browse Source

chore: improve PHPDoc typehints (#7994)

Kuba Werłos 10 months ago
parent
commit
91b20b98e5

+ 0 - 30
dev-tools/phpstan/baseline.php

@@ -376,16 +376,6 @@ $ignoreErrors[] = [
 	'count' => 1,
 	'path' => __DIR__ . '/../../src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php',
 ];
-$ignoreErrors[] = [
-	'message' => '#^Parameter \\#3 \\$indexEnd of method PhpCsFixer\\\\Fixer\\\\FunctionNotation\\\\RegularCallableCallFixer\\:\\:getTokensSubcollection\\(\\) expects int, int\\|false given\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/../../src/Fixer/FunctionNotation/RegularCallableCallFixer.php',
-];
-$ignoreErrors[] = [
-	'message' => '#^Parameter \\#5 \\$firstArgEndIndex of method PhpCsFixer\\\\Fixer\\\\FunctionNotation\\\\RegularCallableCallFixer\\:\\:replaceCallUserFuncWithCallback\\(\\) expects int, int\\|false given\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/../../src/Fixer/FunctionNotation/RegularCallableCallFixer.php',
-];
 $ignoreErrors[] = [
 	'message' => '#^Only numeric types are allowed in \\+, int\\|false given on the left side\\.$#',
 	'count' => 2,
@@ -411,11 +401,6 @@ $ignoreErrors[] = [
 	'count' => 1,
 	'path' => __DIR__ . '/../../src/Fixer/Import/FullyQualifiedStrictTypesFixer.php',
 ];
-$ignoreErrors[] = [
-	'message' => '#^Method PhpCsFixer\\\\Fixer\\\\Import\\\\GlobalNamespaceImportFixer\\:\\:prepareImports\\(\\) should return array\\<string, class\\-string\\> but returns array\\<string, string\\>\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/../../src/Fixer/Import/GlobalNamespaceImportFixer.php',
-];
 $ignoreErrors[] = [
 	'message' => '#^Parameter \\#1 \\$types of method PhpCsFixer\\\\DocBlock\\\\Annotation\\:\\:setTypes\\(\\) expects list\\<string\\>, array\\<int\\<0, max\\>, string\\> given\\.$#',
 	'count' => 1,
@@ -576,11 +561,6 @@ $ignoreErrors[] = [
 	'count' => 5,
 	'path' => __DIR__ . '/../../src/Fixer/PhpUnit/PhpUnitAttributesFixer.php',
 ];
-$ignoreErrors[] = [
-	'message' => '#^Parameter \\#1 \\$slices of method PhpCsFixer\\\\Tokenizer\\\\Tokens\\:\\:insertSlices\\(\\) expects array\\<int, list\\<PhpCsFixer\\\\Tokenizer\\\\Token\\>\\|PhpCsFixer\\\\Tokenizer\\\\Token\\|PhpCsFixer\\\\Tokenizer\\\\Tokens\\>, array\\<\'\'\\|int, array\\{PhpCsFixer\\\\Tokenizer\\\\Token, PhpCsFixer\\\\Tokenizer\\\\Token\\}\\> given\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/../../src/Fixer/PhpUnit/PhpUnitDataProviderStaticFixer.php',
-];
 $ignoreErrors[] = [
 	'message' => '#^Cannot call method isGivenKind\\(\\) on PhpCsFixer\\\\Tokenizer\\\\Token\\|false\\.$#',
 	'count' => 1,
@@ -616,11 +596,6 @@ $ignoreErrors[] = [
 	'count' => 1,
 	'path' => __DIR__ . '/../../src/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixer.php',
 ];
-$ignoreErrors[] = [
-	'message' => '#^Method PhpCsFixer\\\\Fixer\\\\Phpdoc\\\\NoSuperfluousPhpdocTagsFixer\\:\\:getArgumentsInfo\\(\\) should return array\\<non\\-empty\\-string, array\\{types\\: list\\<string\\>, allows_null\\: bool\\}\\> but returns array\\<string, array\\{types\\: list\\<string\\>, allows_null\\: bool\\}\\>\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/../../src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php',
-];
 $ignoreErrors[] = [
 	'message' => '#^Method PhpCsFixer\\\\Fixer\\\\Phpdoc\\\\PhpdocAlignFixer\\:\\:getMatches\\(\\) should return array\\{indent\\: string\\|null, tag\\: string\\|null, hint\\: string, var\\: string\\|null, static\\: string, desc\\?\\: string\\|null\\}\\|null but returns array\\<string\\>\\.$#',
 	'count' => 1,
@@ -666,11 +641,6 @@ $ignoreErrors[] = [
 	'count' => 1,
 	'path' => __DIR__ . '/../../src/Fixer/Phpdoc/PhpdocTagTypeFixer.php',
 ];
-$ignoreErrors[] = [
-	'message' => '#^Parameter \\#1 \\$parts of method PhpCsFixer\\\\Fixer\\\\Phpdoc\\\\PhpdocTagTypeFixer\\:\\:tagIsSurroundedByText\\(\\) expects list\\<string\\>, array\\<int\\<0, max\\>, string\\> given\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/../../src/Fixer/Phpdoc/PhpdocTagTypeFixer.php',
-];
 $ignoreErrors[] = [
 	'message' => '#^Property PhpCsFixer\\\\Fixer\\\\Phpdoc\\\\PhpdocToCommentFixer\\:\\:\\$ignoredTags \\(list\\<string\\>\\) does not accept array\\<string\\>\\.$#',
 	'count' => 1,

+ 1 - 1
src/Fixer/FunctionNotation/RegularCallableCallFixer.php

@@ -103,7 +103,7 @@ call_user_func(static function ($a, $b) { var_dump($a, $b); }, 1, 2);
     }
 
     /**
-     * @param array<int, int> $arguments
+     * @param non-empty-array<int, int> $arguments
      */
     private function processCall(Tokens $tokens, int $index, array $arguments): void
     {

+ 1 - 0
src/Fixer/Import/GlobalNamespaceImportFixer.php

@@ -424,6 +424,7 @@ if (count($x)) {
         $imports = [];
 
         foreach ($indices as $index) {
+            /** @var class-string $name */
             $name = $tokens[$index]->getContent();
             $checkName = $caseSensitive ? $name : strtolower($name);
 

+ 2 - 0
src/Fixer/PhpUnit/PhpUnitDataProviderStaticFixer.php

@@ -117,6 +117,8 @@ class FooTest extends TestCase {
                     continue;
                 }
             }
+
+            /** @var int $functionIndex */
             $functionIndex = $tokens->getPrevTokenOfKind($dataProviderDefinitionIndex->getNameIndex(), [[T_FUNCTION]]);
 
             $methodAttributes = $tokensAnalyzer->getMethodAttributes($functionIndex);

+ 2 - 0
src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php

@@ -467,6 +467,8 @@ class Foo {
         if (true === $this->configuration['allow_hidden_params']) {
             $paramsString = $tokens->generatePartialCode($start, $end);
             Preg::matchAll('|/\*[^$]*(\$\w+)[^*]*\*/|', $paramsString, $matches);
+
+            /** @var non-empty-string $match */
             foreach ($matches[1] as $match) {
                 $argumentsInfo[$match] = self::NO_TYPE_INFO; // HINT: one could try to extract actual type for hidden param, for now we only indicate it's existence
             }

+ 1 - 1
src/Fixer/Phpdoc/PhpdocTagTypeFixer.php

@@ -182,7 +182,7 @@ final class PhpdocTagTypeFixer extends AbstractFixer implements ConfigurableFixe
     }
 
     /**
-     * @param list<string> $parts
+     * @param array<int,string> $parts
      */
     private function tagIsSurroundedByText(array $parts, int $index): bool
     {