Skip to content

Commit e2805d7

Browse files
committed
tweak
1 parent a1597e0 commit e2805d7

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,18 @@ public function processNode(Node $node, Scope $scope): array
8989

9090
$duplicate = false;
9191
$newValues = $keyValues;
92-
foreach ($seenKeys as $seenKey) {
93-
$offset = array_search($seenKey, $newValues, true);
94-
if ($offset !== false) {
95-
unset($newValues[$offset]);
92+
foreach ($newValues as $k => $newValue) {
93+
if (array_search($newValue, $seenKeys, true) !== false) {
94+
unset($newValues[$k]);
9695
}
9796

98-
if (
99-
$newValues === []
100-
) {
97+
if ($newValues === []) {
10198
$duplicate = true;
10299
break;
103100
}
104101
}
105102

106-
if (
107-
$newValues !== []
108-
) {
103+
if ($newValues !== []) {
109104
if (count($newValues) === 1) {
110105
$newValue = $newValues[array_key_first($newValues)];
111106
foreach ($seenUnions as $k => $union) {
@@ -116,12 +111,12 @@ public function processNode(Node $node, Scope $scope): array
116111

117112
unset($seenUnions[$k][$offset]);
118113

114+
// turn a union into a seen key, when all its elements have been seen
119115
if (count($seenUnions[$k]) !== 1) {
120116
continue;
121117
}
122118

123-
$ukey = array_key_first($seenUnions[$k]);
124-
$seenKeys[] = $seenUnions[$k][$ukey];
119+
$seenKeys[] = $seenUnions[$k][array_key_first($seenUnions[$k])];
125120
unset($seenUnions[$k]);
126121
}
127122
$seenKeys[] = $newValue;

0 commit comments

Comments
 (0)