Skip to content

Commit

Permalink
chore: improve PHPDoc typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed May 8, 2024
1 parent 61f5c8a commit b53ac3f
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 32 deletions.
30 changes: 0 additions & 30 deletions dev-tools/phpstan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,6 @@
'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,
Expand All @@ -411,11 +401,6 @@
'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,
Expand Down Expand Up @@ -576,11 +561,6 @@
'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,
Expand Down Expand Up @@ -616,11 +596,6 @@
'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,
Expand Down Expand Up @@ -666,11 +641,6 @@
'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,
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/FunctionNotation/RegularCallableCallFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
}

/**
* @param array<int, int> $arguments
* @param non-empty-array<int, int> $arguments
*/
private function processCall(Tokens $tokens, int $index, array $arguments): void
{
Expand Down
1 change: 1 addition & 0 deletions src/Fixer/Import/GlobalNamespaceImportFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ private function prepareImports(Tokens $tokens, array $indices, array $global, a
$imports = [];

foreach ($indices as $index) {
/** @var class-string $name */
$name = $tokens[$index]->getContent();
$checkName = $caseSensitive ? $name : strtolower($name);

Expand Down
2 changes: 2 additions & 0 deletions src/Fixer/PhpUnit/PhpUnitDataProviderStaticFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en
continue;
}
}

/** @var int $functionIndex */
$functionIndex = $tokens->getPrevTokenOfKind($dataProviderDefinitionIndex->getNameIndex(), [[T_FUNCTION]]);

$methodAttributes = $tokensAnalyzer->getMethodAttributes($functionIndex);
Expand Down
2 changes: 2 additions & 0 deletions src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ private function getArgumentsInfo(Tokens $tokens, int $start, int $end): array
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
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/PhpdocTagTypeFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn
}

/**
* @param list<string> $parts
* @param array<int,string> $parts
*/
private function tagIsSurroundedByText(array $parts, int $index): bool
{
Expand Down

0 comments on commit b53ac3f

Please sign in to comment.