Skip to content

Commit f4ad678

Browse files
committed
Fix
1 parent ec05c6d commit f4ad678

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Fixer/TypedClassConstantFixer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ private static function getTypeOfExpression(Tokens $tokens, int $index): string
118118
$index = $tokens->getNextMeaningfulToken($index);
119119
\assert(\is_int($index));
120120

121-
if ($tokens[$index]->isGivenKind([\T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN])) {
122-
return 'array';
123-
}
124-
125121
do {
126122
$foundKinds[] = $tokens[$index]->getId() ?? $tokens[$index]->getContent();
127123

@@ -144,6 +140,10 @@ private static function getTypeOfExpression(Tokens $tokens, int $index): string
144140
*/
145141
private static function getTypeOfExpressionForTokenKinds(array $tokenKinds): string
146142
{
143+
if (self::isOfTypeBasedOnKinds($tokenKinds, [], [\T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN])) {
144+
return 'array';
145+
}
146+
147147
if (self::isOfTypeBasedOnKinds($tokenKinds, self::INTEGER_KINDS, [])) {
148148
return 'int';
149149
}

tests/Fixer/TypedClassConstantFixerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ class Bar {
192192
];
193193

194194
yield 'constant that can be of different types' => [
195-
'<?php class Foo { public const mixed BAR = SHOULD_BE_INT ? 1 : "one"; }',
196-
'<?php class Foo { public const BAR = SHOULD_BE_INT ? 1 : "one"; }',
195+
'<?php class Foo { public const mixed BAR = SHOULD_BE_INT ? 1 : ["one"]; }',
196+
'<?php class Foo { public const BAR = SHOULD_BE_INT ? 1 : ["one"]; }',
197197
];
198198

199199
yield 'constant that can be of different types - more complex case' => [

0 commit comments

Comments
 (0)