Skip to content

Commit

Permalink
chore: fix phpdoc types (#7977)
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed May 1, 2024
1 parent f81d4f8 commit 633e40c
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 68 deletions.
32 changes: 1 addition & 31 deletions dev-tools/phpstan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@
'count' => 1,
'path' => __DIR__ . '/../../src/Console/WarningsDetector.php',
];
$ignoreErrors[] = [
'message' => '#^Property PhpCsFixer\\\\DocBlock\\\\Annotation\\:\\:\\$end \\(int\\) does not accept int\\|string\\|false\\.$#',
'count' => 1,
'path' => __DIR__ . '/../../src/DocBlock/Annotation.php',
];
$ignoreErrors[] = [
'message' => '#^Only numeric types are allowed in \\+, int\\|false given on the left side\\.$#',
'count' => 1,
Expand Down Expand Up @@ -377,32 +372,7 @@
'path' => __DIR__ . '/../../src/Fixer/ClassNotation/ProtectedToPrivateFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Only numeric types are allowed in \\-, int\\|false given on the left side\\.$#',
'count' => 1,
'path' => __DIR__ . '/../../src/Fixer/Comment/CommentToPhpdocFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Only numeric types are allowed in pre\\-increment, int\\|false given\\.$#',
'count' => 2,
'path' => __DIR__ . '/../../src/Fixer/Comment/CommentToPhpdocFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$index of method PhpCsFixer\\\\Tokenizer\\\\Tokens\\:\\:clearAt\\(\\) expects int, int\\|false given\\.$#',
'count' => 1,
'path' => __DIR__ . '/../../src/Fixer/Comment/CommentToPhpdocFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$index of method PhpCsFixer\\\\Tokenizer\\\\Tokens\\:\\:insertAt\\(\\) expects int, int\\|false given\\.$#',
'count' => 1,
'path' => __DIR__ . '/../../src/Fixer/Comment/CommentToPhpdocFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\.\\.\\.\\$arg1 of function max expects non\\-empty\\-array, array\\<int\\> given\\.$#',
'count' => 1,
'path' => __DIR__ . '/../../src/Fixer/Comment/CommentToPhpdocFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\.\\.\\.\\$arg1 of function max expects non\\-empty\\-array, list\\<int\\> given\\.$#',
'message' => '#^Property PhpCsFixer\\\\Fixer\\\\Comment\\\\CommentToPhpdocFixer\\:\\:\\$ignoredTags \\(list\\<string\\>\\) does not accept array\\<string\\>\\.$#',
'count' => 1,
'path' => __DIR__ . '/../../src/Fixer/Comment/CommentToPhpdocFixer.php',
];
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractNoUselessElseFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function isSuperfluousElse(Tokens $tokens, int $index): bool
*
* @param int $index T_IF, T_ELSE, T_ELSEIF
*
* @return int[]
* @return array{int, int}
*/
private function getPreviousBlock(Tokens $tokens, int $index): array
{
Expand Down
30 changes: 16 additions & 14 deletions src/Console/Command/DescribeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private function describeRule(OutputInterface $output, string $name): void
$output->writeln('');
}

/** @var CodeSampleInterface[] $codeSamples */
/** @var list<CodeSampleInterface> $codeSamples */
$codeSamples = array_filter($definition->getCodeSamples(), static function (CodeSampleInterface $codeSample): bool {
if ($codeSample instanceof VersionSpecificCodeSampleInterface) {
return $codeSample->isSuitableFor(\PHP_VERSION_ID);
Expand Down Expand Up @@ -431,23 +431,25 @@ private function getSetNames(): array
*/
private function describeList(OutputInterface $output, string $type): void
{
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
$describe = [
'sets' => $this->getSetNames(),
'rules' => $this->getFixers(),
];
} elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$describe = 'set' === $type ? ['sets' => $this->getSetNames()] : ['rules' => $this->getFixers()];
} else {
if ($output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) {
return;
}

/** @var string[] $items */
foreach ($describe as $list => $items) {
$output->writeln(sprintf('<comment>Defined %s:</comment>', $list));
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE || 'set' === $type) {
$output->writeln('<comment>Defined sets:</comment>');

$items = $this->getSetNames();
foreach ($items as $item) {
$output->writeln(sprintf('* <info>%s</info>', $item));
}
}

if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE || 'rule' === $type) {
$output->writeln('<comment>Defined rules:</comment>');

foreach ($items as $name => $item) {
$output->writeln(sprintf('* <info>%s</info>', \is_string($name) ? $name : $item));
$items = array_keys($this->getFixers());
foreach ($items as $item) {
$output->writeln(sprintf('* <info>%s</info>', $item));
}
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/DocBlock/Annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class Annotation
/**
* The lines that make up the annotation.
*
* @var Line[]
* @var array<int, Line>
*/
private array $lines;

Expand Down Expand Up @@ -91,27 +91,25 @@ final class Annotation
private $namespace;

/**
* @var NamespaceUseAnalysis[]
* @var list<NamespaceUseAnalysis>
*/
private array $namespaceUses;

/**
* Create a new line instance.
*
* @param Line[] $lines
* @param null|NamespaceAnalysis $namespace
* @param NamespaceUseAnalysis[] $namespaceUses
* @param array<int, Line> $lines
* @param null|NamespaceAnalysis $namespace
* @param list<NamespaceUseAnalysis> $namespaceUses
*/
public function __construct(array $lines, $namespace = null, array $namespaceUses = [])
{
$this->lines = array_values($lines);
$this->namespace = $namespace;
$this->namespaceUses = $namespaceUses;

$keys = array_keys($lines);

$this->start = $keys[0];
$this->end = end($keys);
$this->start = array_key_first($lines);
$this->end = array_key_last($lines);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Basic/NonPrintableCharacterFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
final class NonPrintableCharacterFixer extends AbstractFixer implements ConfigurableFixerInterface
{
/**
* @var array<string, string[]>
* @var array<string, array{string, string}>
*/
private array $symbolsReplace;

Expand Down
12 changes: 6 additions & 6 deletions src/Fixer/Comment/CommentToPhpdocFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
final class CommentToPhpdocFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface
{
/**
* @var string[]
* @var list<string>
*/
private array $ignoredTags = [];

Expand Down Expand Up @@ -124,7 +124,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
}

/**
* @param int[] $indices
* @param list<int> $indices
*/
private function isCommentCandidate(Tokens $tokens, array $indices): bool
{
Expand All @@ -145,12 +145,12 @@ function (bool $carry, int $index) use ($tokens): bool {
}

/**
* @param int[] $indices
* @param non-empty-list<int> $indices
*/
private function fixComment(Tokens $tokens, array $indices): void
{
if (1 === \count($indices)) {
$this->fixCommentSingleLine($tokens, reset($indices));
$this->fixCommentSingleLine($tokens, $indices[0]);
} else {
$this->fixCommentMultiLine($tokens, $indices);
}
Expand All @@ -172,11 +172,11 @@ private function fixCommentSingleLine(Tokens $tokens, int $index): void
}

/**
* @param int[] $indices
* @param non-empty-list<int> $indices
*/
private function fixCommentMultiLine(Tokens $tokens, array $indices): void
{
$startIndex = reset($indices);
$startIndex = $indices[0];
$indent = Utils::calculateTrailingWhitespaceIndent($tokens[$startIndex - 1]);

$newContent = '/**'.$this->whitespacesConfig->getLineEnding();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected function fixAnnotations(Tokens $doctrineAnnotationTokens): void
}

/**
* @return int[]
* @return array{int, int}
*/
private function getLineBracesCount(Tokens $tokens, int $index): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Import/GlobalNamespaceImportFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private function importClasses(Tokens $tokens, array $useDeclarations): array
{
[$global, $other] = $this->filterUseDeclarations($useDeclarations, static fn (NamespaceUseAnalysis $declaration): bool => $declaration->isClass(), false);

/** @var DocBlock[] $docBlocks */
/** @var array<int, DocBlock> $docBlocks */
$docBlocks = [];

// find class declarations and class usages in docblocks
Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
}

/**
* @param int[] $indices
* @param list<int> $indices
*/
private function clearOffsetTokens(Tokens $tokens, int $offset, array $indices): void
{
Expand All @@ -112,7 +112,7 @@ private function clearOffsetTokens(Tokens $tokens, int $offset, array $indices):
*
* Or the index to where the method looked for a call.
*
* @return int|int[]
* @return array{int, int, int, int}|int
*/
private function getPreviousUnsetCall(Tokens $tokens, int $index)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Preg.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static function matchAll(string $pattern, string $subject, ?array &$match
}

/**
* @param string|string[] $subject
* @param array<array-key, string>|string $subject
*
* @param-out int $count
*
Expand Down
2 changes: 1 addition & 1 deletion src/Tokenizer/Analyzer/CommentsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function isBeforeReturn(Tokens $tokens, int $index): bool
*
* @param int $index T_COMMENT index
*
* @return list<int>
* @return non-empty-list<int>
*/
public function getCommentBlockIndices(Tokens $tokens, int $index): array
{
Expand Down

0 comments on commit 633e40c

Please sign in to comment.