From cc807749840833bee8e39932ecc809fcae32a161 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 16 Dec 2024 20:22:08 +0700 Subject: [PATCH] [Php81] Skip reassign on array destruct on ReadOnlyPropertyRector --- .../skip_reassign_on_array_destruct.php.inc | 15 +++++++++++++++ .../Scope/NodeVisitor/AssignedToNodeVisitor.php | 7 +++++++ 2 files changed, 22 insertions(+) create mode 100644 rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_reassign_on_array_destruct.php.inc diff --git a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_reassign_on_array_destruct.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_reassign_on_array_destruct.php.inc new file mode 100644 index 00000000000..b1e65729f0d --- /dev/null +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_reassign_on_array_destruct.php.inc @@ -0,0 +1,15 @@ +selectedFrom, $this->selectedTo] = [0, 1]; + [$this->selectedFrom, $this->selectedTo] = [0, 1]; + } +} \ No newline at end of file diff --git a/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/AssignedToNodeVisitor.php b/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/AssignedToNodeVisitor.php index 7bbff4f4a4e..7719e95149c 100644 --- a/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/AssignedToNodeVisitor.php +++ b/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/AssignedToNodeVisitor.php @@ -8,6 +8,7 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\AssignOp; use PhpParser\Node\Expr\AssignRef; +use PhpParser\Node\Expr\List_; use PhpParser\NodeVisitorAbstract; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface; @@ -34,6 +35,12 @@ public function enterNode(Node $node): ?Node } $node->var->setAttribute(AttributeKey::IS_BEING_ASSIGNED, true); + if ($node->var instanceof List_) { + foreach ($node->var->items as $item) { + $item->value->setAttribute(AttributeKey::IS_BEING_ASSIGNED, true); + } + } + $node->expr->setAttribute(AttributeKey::IS_ASSIGNED_TO, true); if ($node->expr instanceof Assign) {