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: more types #7598

Merged
merged 13 commits into from
Dec 20, 2023
2 changes: 1 addition & 1 deletion dev-tools/phpstan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@
'path' => __DIR__ . '/../../src/Tokenizer/Tokens.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$array \\(array\\<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\\(\\)$#',
'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,
'path' => __DIR__ . '/../../src/Tokenizer/Tokens.php',
];
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractFunctionReferenceFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function isRisky(): bool
* Looks up Tokens sequence for suitable candidates and delivers boundaries information,
* which can be supplied by other methods in this abstract class.
*
* @return null|int[] returns $functionName, $openParenthesis, $closeParenthesis packed into array
* @return ?array{int, int, int} returns $functionName, $openParenthesis, $closeParenthesis packed into array
*/
protected function find(string $functionNameToSearch, Tokens $tokens, int $start = 0, ?int $end = null): ?array
{
Expand Down
4 changes: 2 additions & 2 deletions src/AbstractPhpdocToTypeDeclarationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function findFunctionDocComment(Tokens $tokens, int $index): ?int
}

/**
* @return Annotation[]
* @return list<Annotation>
*/
protected function getAnnotationsFromDocComment(string $name, Tokens $tokens, int $docCommentIndex): array
{
Expand All @@ -123,7 +123,7 @@ protected function getAnnotationsFromDocComment(string $name, Tokens $tokens, in
}

/**
* @return Token[]
* @return list<Token>
*/
protected function createTypeDeclarationTokens(string $type, bool $isNullable): array
{
Expand Down
15 changes: 7 additions & 8 deletions src/AbstractPhpdocTypesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class AbstractPhpdocTypesFixer extends AbstractFixer
/**
* The annotation tags search inside.
*
* @var string[]
* @var list<string>
*/
protected array $tags;

Expand Down Expand Up @@ -93,17 +93,16 @@ private function fixTypes(Annotation $annotation): void
}

/**
* @param string[] $types
* @param list<string> $types
*
* @return string[]
* @return list<string>
*/
private function normalizeTypes(array $types): array
{
foreach ($types as $index => $type) {
$types[$index] = $this->normalizeType($type);
}

return $types;
return array_map(
fn (string $type): string => $this->normalizeType($type),
$types
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function toJson(): string
'hashes' => $this->hashes,
]);

if (JSON_ERROR_NONE !== json_last_error()) {
if (JSON_ERROR_NONE !== json_last_error() || false === $json) {
throw new \UnexpectedValueException(sprintf(
'Cannot encode cache signature to JSON, error: "%s". If you have non-UTF8 chars in your signature, like in license for `header_comment`, consider enabling `ext-mbstring` or install `symfony/polyfill-mbstring`.',
json_last_error_msg()
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/DescribeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final class DescribeCommand extends Command
protected static $defaultName = 'describe';

/**
* @var string[]
* @var ?list<string>
*/
private $setNames;

Expand Down Expand Up @@ -400,7 +400,7 @@ private function getFixers(): array
}

/**
* @return string[]
* @return list<string>
*/
private function getSetNames(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Console/ConfigurationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ public function configFinderIsOverridden(): bool
/**
* Compute file candidates for config file.
*
* @return string[]
* @return list<string>
*/
private function computeConfigFiles(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Console/WarningsDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function detectOldVendor(): void
}

/**
* @return string[]
* @return list<string>
*/
public function getWarnings(): array
{
Expand Down
12 changes: 6 additions & 6 deletions src/DocBlock/Annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class Annotation
/**
* All the annotation tag names with types.
*
* @var string[]
* @var list<string>
*/
private static array $tags = [
'method',
Expand Down Expand Up @@ -81,7 +81,7 @@ final class Annotation
/**
* The cached types.
*
* @var null|string[]
* @var null|list<string>
*/
private $types;

Expand Down Expand Up @@ -125,7 +125,7 @@ public function __toString(): string
/**
* Get all the annotation tag names with types.
*
* @return string[]
* @return list<string>
*/
public static function getTagsWithTypes(): array
{
Expand Down Expand Up @@ -192,7 +192,7 @@ public function getVariableName()
/**
* Get the types associated with this annotation.
*
* @return string[]
* @return list<string>
*/
public function getTypes(): array
{
Expand All @@ -209,7 +209,7 @@ public function getTypes(): array
/**
* Set the types associated with this annotation.
*
* @param string[] $types
* @param list<string> $types
*/
public function setTypes(array $types): void
{
Expand All @@ -223,7 +223,7 @@ public function setTypes(array $types): void
/**
* Get the normalized types associated with this annotation, so they can easily be compared.
*
* @return string[]
* @return list<string>
*/
public function getNormalizedTypes(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/DocBlock/TypeExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function toString(): string
}

/**
* @return string[]
* @return list<string>
*/
public function getTypes(): array
{
Expand Down
8 changes: 4 additions & 4 deletions src/Error/ErrorsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
final class ErrorsManager
{
/**
* @var Error[]
* @var list<Error>
*/
private array $errors = [];

/**
* Returns errors reported during linting before fixing.
*
* @return Error[]
* @return list<Error>
*/
public function getInvalidErrors(): array
{
Expand All @@ -41,7 +41,7 @@ public function getInvalidErrors(): array
/**
* Returns errors reported during fixing.
*
* @return Error[]
* @return list<Error>
*/
public function getExceptionErrors(): array
{
Expand All @@ -51,7 +51,7 @@ public function getExceptionErrors(): array
/**
* Returns errors reported during linting after fixing.
*
* @return Error[]
* @return list<Error>
*/
public function getLintErrors(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Alias/PowToExponentiationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private function isParenthesisNeeded(Tokens $tokens, int $argumentStartIndex, in
}

/**
* @return int[]
* @return list<int>
*/
private function getAllowedKinds(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private function fixTraitUse(Tokens $tokens, int $useTraitIndex, array $candidat
}

/**
* @return int[]
* @return list<int>
*/
private function getCandidates(Tokens $tokens, int $index): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/DeprecatedFixerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface DeprecatedFixerInterface extends FixerInterface
/**
* Returns names of fixers to use instead, if any.
*
* @return string[]
* @return list<string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
public function getSuccessorsNames(): array;
}
4 changes: 2 additions & 2 deletions src/Fixer/FunctionNotation/FopenFlagOrderFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ protected function fixFopenFlagToken(Tokens $tokens, int $argumentStartIndex, in
}

/**
* @param string[] $flags
* @param list<string> $flags
*
* @return string[]
* @return list<string>
*/
private function sortFlags(array $flags): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private function getBraceAfterVariableKinds(): array
/**
* Gets the token kinds which can work as function calls.
*
* @return int[] Token names
* @return list<int> Token names
*/
private function getFunctionyTokenKinds(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/FunctionNotation/VoidReturnFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private function fixFunctionDefinition(Tokens $tokens, int $index): void
*
* @param int $index The index of the function token
*
* @return Annotation[]
* @return list<Annotation>
*/
private function findReturnAnnotations(Tokens $tokens, int $index): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Import/FullyQualifiedStrictTypesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ private function getTypes(Tokens $tokens, int $index, int $endIndex): iterable
}

/**
* @return Token[]
* @return list<Token>
*/
private function namespacedStringToTokens(string $input, bool $withLeadingBackslash = false): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Import/SingleImportPerStatementFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private function getGroupDeclaration(Tokens $tokens, int $index): array
}

/**
* @return string[]
* @return list<string>
*/
private function getGroupStatements(Tokens $tokens, string $groupPrefix, int $groupOpenIndex, int $groupCloseIndex, string $comment): array
{
Expand Down
6 changes: 3 additions & 3 deletions src/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
}

/**
* @param int[] $indices
* @param list<int> $indices
*/
private function clearTokens(Tokens $tokens, array $indices): void
{
Expand Down Expand Up @@ -146,9 +146,9 @@ private function getIssetInfo(Tokens $tokens, int $index): array
}

/**
* @param int[] $indices
* @param list<int> $indices
*
* @return Token[]
* @return list<Token>
*/
private function getTokenClones(Tokens $tokens, array $indices): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/PhpTag/EchoTagSyntaxFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private function isComplexCode(Tokens $tokens, int $index): bool
/**
* Builds the list of tokens that replace a long echo sequence.
*
* @return Token[]
* @return list<Token>
*/
private function buildLongToShortTokens(Tokens $tokens, int $openTagIndex, int $echoTagIndex): array
{
Expand Down
6 changes: 3 additions & 3 deletions src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private function createDocBlock(Tokens $tokens, int $docBlockIndex): void
}

/**
* @return Line[]
* @return list<Line>
*/
private function updateDocBlock(Tokens $tokens, int $docBlockIndex): array
{
Expand All @@ -236,9 +236,9 @@ private function updateDocBlock(Tokens $tokens, int $docBlockIndex): array
}

/**
* @param Line[] $lines
* @param list<Line> $lines
*
* @return Line[]
* @return list<Line>
*/
private function updateLines(array $lines, Tokens $tokens, int $docBlockIndex): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/Phpdoc/PhpdocParamOrderFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private function rewriteDocBlock(DocBlock $doc, array $paramNames, array $paramA
* @param Token[] $funcParamNames
* @param Annotation[] $paramAnnotations
*
* @return string[]
* @return list<string>
*/
private function sortParamAnnotations(array $funcParamNames, array $paramAnnotations): array
{
Expand Down Expand Up @@ -199,7 +199,7 @@ private function sortParamAnnotations(array $funcParamNames, array $paramAnnotat
*
* @param Annotation[] $paramAnnotations
*
* @return string[]
* @return list<string>
*/
private function getOtherAnnotationsBetweenParams(DocBlock $doc, array $paramAnnotations): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
}

/**
* @return string[]
* @return list<string>
*/
private function sortTypes(TypeExpression $typeExpression): array
{
Expand Down
7 changes: 5 additions & 2 deletions src/FixerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function registerBuiltInFixers(): self
static $builtInFixers = null;

if (null === $builtInFixers) {
/** @var list<class-string<FixerInterface>> */
$builtInFixers = [];

/** @var SplFileInfo $file */
Expand All @@ -94,7 +95,9 @@ public function registerBuiltInFixers(): self
}

foreach ($builtInFixers as $class) {
$this->registerFixer(new $class(), false);
/** @var FixerInterface */
$fixer = new $class();
$this->registerFixer($fixer, false);
}

return $this;
Expand Down Expand Up @@ -195,7 +198,7 @@ public function hasRule(string $name): bool
}

/**
* @return string[]
* @return list<string>
*/
private function getFixersConflicts(FixerInterface $fixer): array
{
Expand Down
Loading