Skip to content

Commit

Permalink
[Php81] Skip reassign on array destruct on ReadOnlyPropertyRector
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Dec 16, 2024
1 parent 3e2e579 commit cc80774
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture;

class SkipReassignOnArrayDestruct
{
private int $selectedFrom;
private int $selectedTo;

public function run()
{
[$this->selectedFrom, $this->selectedTo] = [0, 1];
[$this->selectedFrom, $this->selectedTo] = [0, 1];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit cc80774

Please sign in to comment.