Skip to content

Commit

Permalink
Support more assign cases in PropertyFetchAssignManipulator (#6192)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersonamuller committed Jul 28, 2024
1 parent 56f4768 commit 0c06da9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

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

final class SkipAssignOp
{
private string $name;
private int $count;

public function __construct(string $name, bool $flag = false)
{
$this->name = $name;

if ($flag) {
$this->name .= 'changed';
}

$this->count = 0;
if ($flag) {
++$this->count;
}
}
}
3 changes: 2 additions & 1 deletion src/NodeManipulator/PropertyFetchAssignManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\AssignOp;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
Expand Down Expand Up @@ -43,7 +44,7 @@ function (Node $node) use ($propertyName, &$count): ?int {
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}

if (! $node instanceof Assign) {
if (! $node instanceof Assign && ! $node instanceof AssignOp) {
return null;
}

Expand Down

0 comments on commit 0c06da9

Please sign in to comment.