From 693ecaa597a786ec3c01535f5bc727847e8c8853 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 1 Nov 2026 14:18:17 +0700 Subject: [PATCH 1/2] [refactor] Remove unneded origNode check on ArrayMergeFromArraySpreadFactor --- .../ArrayMergeFromArraySpreadFactory.php | 28 +------------------ 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php index f2166018..e0e3c6c0 100644 --- a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php +++ b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php @@ -9,23 +9,14 @@ use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Ternary; -use PhpParser\Node\Expr\Variable; use PhpParser\Node\Name; use PHPStan\Analyser\MutatingScope; use PHPStan\Type\IterableType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; -use Rector\Exception\ShouldNotHappenException; -use Rector\NodeNameResolver\NodeNameResolver; -use Rector\NodeTypeResolver\Node\AttributeKey; final readonly class ArrayMergeFromArraySpreadFactory { - public function __construct( - private NodeNameResolver $nodeNameResolver - ) { - } - public function createFromArray(Array_ $array, MutatingScope $mutatingScope): FuncCall { $newArrayItems = $this->dissolveArrayItems($array); @@ -100,24 +91,7 @@ private function createArrayItemFromArray(array $items): ArrayItem private function createArgFromSpreadArrayItem(MutatingScope $mutatingScope, ArrayItem $arrayItem): Arg { - // By now every item is a variable - /** @var Variable $variable */ - $variable = $arrayItem->value; - - $variableName = $this->nodeNameResolver->getName($variable) ?? ''; - - // If the variable is not in scope, it's one we just added. - // Then get the type from the attribute - if ($mutatingScope->hasVariableType($variableName)->yes()) { - $type = $mutatingScope->getVariableType($variableName); - } else { - $originalNode = $arrayItem->getAttribute(AttributeKey::ORIGINAL_NODE); - if ($originalNode instanceof ArrayItem) { - $type = $mutatingScope->getType($originalNode->value); - } else { - throw new ShouldNotHappenException(); - } - } + $type = $mutatingScope->getType($arrayItem->value); $iteratorToArrayFuncCall = new FuncCall(new Name('iterator_to_array'), [new Arg($arrayItem->value)]); From f3e982b7a167ffa7af6658df649e0a65441a5ddb Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 1 Nov 2026 14:18:21 +0700 Subject: [PATCH 2/2] [refactor] Fix property same name as variable array spread on DowngradeArraySpreadRector --- .../property_same_name_as_variable.php.inc | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 rules-tests/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector/Fixture/property_same_name_as_variable.php.inc diff --git a/rules-tests/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector/Fixture/property_same_name_as_variable.php.inc b/rules-tests/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector/Fixture/property_same_name_as_variable.php.inc new file mode 100644 index 00000000..3011e192 --- /dev/null +++ b/rules-tests/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector/Fixture/property_same_name_as_variable.php.inc @@ -0,0 +1,39 @@ +items, ...$items]; + } +} + +?> +----- +items), $items); + } +} + +?>