|
9 | 9 | use PHPStan\Rules\Rule; |
10 | 10 | use PHPStan\Rules\RuleErrorBuilder; |
11 | 11 | use PHPStan\Type\Constant\ConstantIntegerType; |
12 | | -use PHPStan\Type\NeverType; |
13 | | -use PHPStan\Type\TypeCombinator; |
14 | | -use PHPStan\Type\UnionType; |
| 12 | +use function array_key_first; |
15 | 13 | use function array_keys; |
| 14 | +use function array_search; |
16 | 15 | use function count; |
17 | 16 | use function implode; |
18 | 17 | use function is_int; |
@@ -89,41 +88,45 @@ public function processNode(Node $node, Scope $scope): array |
89 | 88 | } |
90 | 89 |
|
91 | 90 | $duplicate = false; |
92 | | - $newValuesType = $keyValues; |
| 91 | + $newValues = $keyValues; |
93 | 92 | foreach ($seenKeys as $seenKey) { |
94 | | - $offset = array_search($seenKey, $newValuesType, true); |
| 93 | + $offset = array_search($seenKey, $newValues, true); |
95 | 94 | if ($offset !== false) { |
96 | | - unset($newValuesType[$offset]); |
| 95 | + unset($newValues[$offset]); |
97 | 96 | } |
98 | 97 |
|
99 | 98 | if ( |
100 | | - $newValuesType === [] |
| 99 | + $newValues === [] |
101 | 100 | ) { |
102 | 101 | $duplicate = true; |
103 | 102 | break; |
104 | 103 | } |
105 | 104 | } |
106 | 105 |
|
107 | 106 | if ( |
108 | | - $newValuesType !== [] |
| 107 | + $newValues !== [] |
109 | 108 | ) { |
110 | | - if (count($newValuesType) === 1) { |
111 | | - $newValue = $newValuesType[array_key_first($newValuesType)]; |
112 | | - foreach ($seenUnions as $k => $seenKey) { |
113 | | - $offset = array_search($newValue, $seenKey, true); |
114 | | - if ($offset !== false) { |
115 | | - unset($seenUnions[$k][$offset]); |
116 | | - |
117 | | - if (count($seenUnions[$k]) === 1) { |
118 | | - $ukey = array_key_first($seenUnions[$k]); |
119 | | - $seenKeys[] = $seenUnions[$k][$ukey]; |
120 | | - unset($seenUnions[$k]); |
121 | | - } |
| 109 | + if (count($newValues) === 1) { |
| 110 | + $newValue = $newValues[array_key_first($newValues)]; |
| 111 | + foreach ($seenUnions as $k => $union) { |
| 112 | + $offset = array_search($newValue, $union, true); |
| 113 | + if ($offset === false) { |
| 114 | + continue; |
122 | 115 | } |
| 116 | + |
| 117 | + unset($seenUnions[$k][$offset]); |
| 118 | + |
| 119 | + if (count($seenUnions[$k]) !== 1) { |
| 120 | + continue; |
| 121 | + } |
| 122 | + |
| 123 | + $ukey = array_key_first($seenUnions[$k]); |
| 124 | + $seenKeys[] = $seenUnions[$k][$ukey]; |
| 125 | + unset($seenUnions[$k]); |
123 | 126 | } |
124 | 127 | $seenKeys[] = $newValue; |
125 | 128 | } else { |
126 | | - $seenUnions[] = $newValuesType; |
| 129 | + $seenUnions[] = $newValues; |
127 | 130 | } |
128 | 131 | } |
129 | 132 |
|
|
0 commit comments