Skip to content

Commit 6b3bec7

Browse files
committed
Fix test
1 parent 7bed9a2 commit 6b3bec7

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

src/Fixer/ClassNotation/VisibilityRequiredFixer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
108108
$tokensAnalyzer = new TokensAnalyzer($tokens);
109109
$elements = $tokensAnalyzer->getClassyElements();
110110

111+
$propertyTypeDeclarationKinds = [T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT];
112+
111113
foreach (array_reverse($elements, true) as $index => $element) {
112114
if (!\in_array($element['type'], $this->configuration['elements'], true)) {
113115
continue;
@@ -121,15 +123,15 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
121123

122124
$expectedKinds = [T_ABSTRACT, T_FINAL, T_PRIVATE, T_PROTECTED, T_PUBLIC, T_STATIC, T_VAR];
123125
if ('property' === $element['type']) {
124-
$expectedKinds = array_merge($expectedKinds, [T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE]);
126+
$expectedKinds = array_merge($expectedKinds, $propertyTypeDeclarationKinds);
125127
}
126128

127129
while ($tokens[$prevIndex]->isGivenKind($expectedKinds)) {
128130
if ($tokens[$prevIndex]->isGivenKind([T_ABSTRACT, T_FINAL])) {
129131
$abstractFinalIndex = $prevIndex;
130132
} elseif ($tokens[$prevIndex]->isGivenKind(T_STATIC)) {
131133
$staticIndex = $prevIndex;
132-
} elseif ($tokens[$prevIndex]->isGivenKind([T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE])) {
134+
} elseif ($tokens[$prevIndex]->isGivenKind($propertyTypeDeclarationKinds)) {
133135
$typeIndex = $prevIndex;
134136
} else {
135137
$visibilityIndex = $prevIndex;

src/Tokenizer/Transformer/NullableTypeTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function process(Tokens $tokens, Token $token, $index)
6363
$prevIndex = $tokens->getPrevMeaningfulToken($index);
6464
$prevToken = $tokens[$prevIndex];
6565

66-
if ($prevToken->equalsAny(['(', ',', [CT::T_TYPE_COLON], [T_PRIVATE], [T_PROTECTED], [T_PUBLIC], [T_VAR]])) {
66+
if ($prevToken->equalsAny(['(', ',', [CT::T_TYPE_COLON], [T_PRIVATE], [T_PROTECTED], [T_PUBLIC], [T_VAR], [T_STATIC]])) {
6767
$tokens[$index] = new Token([CT::T_NULLABLE_TYPE, '?']);
6868
}
6969
}

tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ public function provideFix74Cases()
819819
];
820820
yield [
821821
'<?php class Foo { public static ?array $foo; }',
822+
'<?php class Foo { static public ?array $foo; }',
822823
];
823824
}
824825
}

tests/Tokenizer/Transformer/NullableTypeTransformerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ public function provideProcessPhp74Cases()
149149
16 => CT::T_NULLABLE_TYPE,
150150
],
151151
],
152+
[
153+
'<?php class Foo { public ?array $foo; public static ?array $bar; }',
154+
[
155+
9 => CT::T_NULLABLE_TYPE,
156+
19 => CT::T_NULLABLE_TYPE,
157+
],
158+
],
152159
];
153160
}
154161
}

0 commit comments

Comments
 (0)