Skip to content

Commit f9c163c

Browse files
committed
clean up
1 parent 250b416 commit f9c163c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

rules-tests/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector/Fixture/on_class_constant.php.inc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ abstract class OnClassConstant
2424
{
2525
private const TYPE_END_TOKENS = [')', [T_CALLABLE], [T_NS_SEPARATOR], [T_STATIC], [T_STRING], [CT::T_ARRAY_TYPEHINT]];
2626

27-
private const TYPE_TOKENS = ['|', '&', '(', ')', [T_CALLABLE], [T_NS_SEPARATOR], [T_STATIC], [T_STRING], [CT::T_ARRAY_TYPEHINT], [CT::T_TYPE_ALTERNATION], [CT::T_TYPE_INTERSECTION], [T_WHITESPACE], [T_COMMENT], [T_DOC_COMMENT]];
27+
private const TYPE_TOKENS = [
28+
'|', '&', '(', ')', [T_CALLABLE], [T_NS_SEPARATOR], [T_STATIC], [T_STRING], [CT::T_ARRAY_TYPEHINT],
29+
[CT::T_TYPE_ALTERNATION], [CT::T_TYPE_INTERSECTION],
30+
[T_WHITESPACE], [T_COMMENT], [T_DOC_COMMENT],
31+
];
2832
}
2933

3034
?>

rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,12 @@ private function refactorArrayConstValue(Array_ $array): ?Array_
174174
$hasChanged = false;
175175

176176
$newArray = new Array_();
177+
$newArray->setAttributes($array->getAttributes());
178+
177179
foreach ($array->items as $item) {
180+
$newArray->items[] = $item;
178181
$type = $this->resolveItemType($item);
179182
if (! $type instanceof FullyQualifiedObjectType) {
180-
$newArray->items[] = $item;
181183
continue;
182184
}
183185

@@ -188,7 +190,6 @@ private function refactorArrayConstValue(Array_ $array): ?Array_
188190
/** @var Identifier $name */
189191
$classLike = $this->astResolver->resolveClassFromName($type->getClassName());
190192
if (! $classLike instanceof ClassLike) {
191-
$newArray->items[] = $item;
192193
continue;
193194
}
194195

@@ -198,6 +199,7 @@ private function refactorArrayConstValue(Array_ $array): ?Array_
198199
$const = $constant->consts[0];
199200

200201
if ($const->name->toString() === $name->toString() && $const->value instanceof Array_) {
202+
array_pop($newArray->items);
201203
$newArray->items = array_merge($newArray->items, $const->value->items);
202204

203205
$hasChanged = true;

0 commit comments

Comments
 (0)