Skip to content

Commit 347f4f5

Browse files
authored
Fix types for fixers (#279)
1 parent 6e1b311 commit 347f4f5

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

dev-tools/phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ parameters:
2323
- ../src/Fixer/NumericLiteralSeparatorFixer.php
2424
- ../src/Fixer/OperatorLinebreakFixer.php
2525
- ../src/Fixer/PhpUnitNoUselessReturnFixer.php
26-
- ../src/Fixer/PhpdocNoIncorrectVarAnnotationFixer.php
2726
- ../src/Fixer/PhpdocOnlyAllowedAnnotationsFixer.php
2827
- ../src/Fixer/PhpdocParamTypeFixer.php
2928
- ../src/Fixer/PhpdocSelfAccessorFixer.php

dev-tools/psalm.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
<InvalidArgument errorLevel='suppress' />
2828
<LoopInvalidation errorLevel='suppress' />
2929
<MixedArgument errorLevel='suppress' />
30-
<MixedArgumentTypeCoercion errorLevel='suppress' />
3130
<MixedArrayAccess errorLevel='suppress' />
3231
<MixedAssignment errorLevel='suppress' />
3332
<MixedMethodCall errorLevel='suppress' />

src/Fixer/PhpdocNoIncorrectVarAnnotationFixer.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,19 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
6363
return;
6464
}
6565

66-
if ($tokens[$nextIndex]->isGivenKind([T_PRIVATE, T_PROTECTED, T_PUBLIC, T_VAR, T_STATIC])) {
66+
/** @var Token $nextToken */
67+
$nextToken = $tokens[$nextIndex];
68+
69+
if ($nextToken->isGivenKind([T_PRIVATE, T_PROTECTED, T_PUBLIC, T_VAR, T_STATIC])) {
6770
continue;
6871
}
6972

70-
if ($tokens[$nextIndex]->isGivenKind(T_VARIABLE)) {
71-
$this->removeVarAnnotation($tokens, $index, [$tokens[$nextIndex]->getContent()]);
73+
if ($nextToken->isGivenKind(T_VARIABLE)) {
74+
$this->removeVarAnnotation($tokens, $index, [$nextToken->getContent()]);
7275
continue;
7376
}
7477

75-
if ($tokens[$nextIndex]->isGivenKind([T_FOR, T_FOREACH, T_IF, T_SWITCH, T_WHILE])) {
78+
if ($nextToken->isGivenKind([T_FOR, T_FOREACH, T_IF, T_SWITCH, T_WHILE])) {
7679
$this->removeVarAnnotationForControl($tokens, $index, $nextIndex);
7780
continue;
7881
}
@@ -108,6 +111,7 @@ private function removeVarAnnotationForControl(Tokens $tokens, int $commentIndex
108111
$variables = [];
109112

110113
for ($index = $index + 1; $index < $endIndex; $index++) {
114+
/** @var Token $token */
111115
$token = $tokens[$index];
112116

113117
if ($token->isGivenKind(T_VARIABLE)) {
@@ -120,7 +124,10 @@ private function removeVarAnnotationForControl(Tokens $tokens, int $commentIndex
120124

121125
private function removeVarAnnotationNotMatchingPattern(Tokens $tokens, int $index, ?string $pattern): void
122126
{
123-
$doc = new DocBlock($tokens[$index]->getContent());
127+
/** @var Token $token */
128+
$token = $tokens[$index];
129+
130+
$doc = new DocBlock($token->getContent());
124131

125132
foreach ($doc->getAnnotationsOfType(['var']) as $annotation) {
126133
if ($pattern === null || Preg::match($pattern, $annotation->getContent()) !== 1) {
@@ -130,7 +137,7 @@ private function removeVarAnnotationNotMatchingPattern(Tokens $tokens, int $inde
130137

131138
$content = $doc->getContent();
132139

133-
if ($content === $tokens[$index]->getContent()) {
140+
if ($content === $token->getContent()) {
134141
return;
135142
}
136143

0 commit comments

Comments
 (0)