Skip to content

Commit d2d205f

Browse files
committed
avoid invalid append
1 parent b6569e1 commit d2d205f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,22 @@ private function refactorArrayConstValue(Array_ $array): ?Array_
194194

195195
$constants = $classLike->getConstants();
196196

197+
$hasChangedOnCurrentIteration = false;
197198
foreach ($constants as $constant) {
198199
$const = $constant->consts[0];
199200

200201
if ($const->name->toString() === $name->toString() && $const->value instanceof Array_) {
201202
$newArray->items = array_merge($newArray->items, $const->value->items);
202203

203204
$hasChanged = true;
205+
$hasChangedOnCurrentIteration = true;
204206
}
205207
}
208+
209+
if (! $hasChangedOnCurrentIteration) {
210+
$newArray->items[] = $item;
211+
}
212+
206213
}
207214

208215
if ($hasChanged) {

0 commit comments

Comments
 (0)