Skip to content

Commit a1597e0

Browse files
committed
cs
1 parent 03cb092 commit a1597e0

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
use PHPStan\Rules\Rule;
1010
use PHPStan\Rules\RuleErrorBuilder;
1111
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;
1513
use function array_keys;
14+
use function array_search;
1615
use function count;
1716
use function implode;
1817
use function is_int;
@@ -89,41 +88,45 @@ public function processNode(Node $node, Scope $scope): array
8988
}
9089

9190
$duplicate = false;
92-
$newValuesType = $keyValues;
91+
$newValues = $keyValues;
9392
foreach ($seenKeys as $seenKey) {
94-
$offset = array_search($seenKey, $newValuesType, true);
93+
$offset = array_search($seenKey, $newValues, true);
9594
if ($offset !== false) {
96-
unset($newValuesType[$offset]);
95+
unset($newValues[$offset]);
9796
}
9897

9998
if (
100-
$newValuesType === []
99+
$newValues === []
101100
) {
102101
$duplicate = true;
103102
break;
104103
}
105104
}
106105

107106
if (
108-
$newValuesType !== []
107+
$newValues !== []
109108
) {
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;
122115
}
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]);
123126
}
124127
$seenKeys[] = $newValue;
125128
} else {
126-
$seenUnions[] = $newValuesType;
129+
$seenUnions[] = $newValues;
127130
}
128131
}
129132

0 commit comments

Comments
 (0)