Skip to content

Commit 86f3a9a

Browse files
committed
Update
1 parent 02237b7 commit 86f3a9a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Fixer/ClassConstantUsageFixer.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ private function fixClass(Tokens $tokens, int $openParenthesisIndex, int $closeP
101101
}
102102
}
103103

104+
/**
105+
* @return array{array<string, string>, array<int, true>}
106+
*/
104107
private function getClassConstants(Tokens $tokens, int $openParenthesisIndex, int $closeParenthesisIndex): array
105108
{
106109
$constants = [];
@@ -111,9 +114,13 @@ private function getClassConstants(Tokens $tokens, int $openParenthesisIndex, in
111114
}
112115

113116
$assignTokenIndex = $tokens->getNextTokenOfKind($index, ['=']);
117+
\assert(\is_int($assignTokenIndex));
114118

115119
$constantNameIndex = $tokens->getPrevMeaningfulToken($assignTokenIndex);
120+
\assert(\is_int($constantNameIndex));
121+
116122
$constantValueIndex = $tokens->getNextMeaningfulToken($assignTokenIndex);
123+
\assert(\is_int($constantValueIndex));
117124

118125
$constantsIndices[$constantValueIndex] = true;
119126

@@ -127,17 +134,21 @@ private function getClassConstants(Tokens $tokens, int $openParenthesisIndex, in
127134
return [$this->getClassConstantsMap($constants), $constantsIndices];
128135
}
129136

137+
/**
138+
* @param array<string, string> $constants
139+
*
140+
* @return array<string, string>
141+
*/
130142
private function getClassConstantsMap(array $constants): array
131143
{
132144
$map = [];
133145
$valuesCount = [];
134146

135147
foreach ($constants as $name => $value) {
136148
$map[$value] = $name;
137-
$valuesCount[$value] = $valuesCount[$value] ?? 0;
138-
$valuesCount[$value]++;
149+
$valuesCount[$value] = ($valuesCount[$value] ?? 0) + 1;
139150

140-
if (($valuesCount[$value] ?? 0) > 1) {
151+
if ($valuesCount[$value] > 1) {
141152
unset($map[$value]);
142153
}
143154
}

0 commit comments

Comments
 (0)