diff --git a/rules-tests/DeadCode/Rector/StmtsAwareInterface/RemoveJustPropertyFetchRector/Fixture/skip_append_array_data.php.inc b/rules-tests/DeadCode/Rector/StmtsAwareInterface/RemoveJustPropertyFetchRector/Fixture/skip_append_array_data.php.inc new file mode 100644 index 00000000000..dbd03766fe9 --- /dev/null +++ b/rules-tests/DeadCode/Rector/StmtsAwareInterface/RemoveJustPropertyFetchRector/Fixture/skip_append_array_data.php.inc @@ -0,0 +1,14 @@ +default; + $where[] = 'some append data'; + } +} diff --git a/rules/DeadCode/Rector/StmtsAwareInterface/RemoveJustPropertyFetchRector.php b/rules/DeadCode/Rector/StmtsAwareInterface/RemoveJustPropertyFetchRector.php index 65b8f93aac7..c3c59c2a15c 100644 --- a/rules/DeadCode/Rector/StmtsAwareInterface/RemoveJustPropertyFetchRector.php +++ b/rules/DeadCode/Rector/StmtsAwareInterface/RemoveJustPropertyFetchRector.php @@ -22,6 +22,7 @@ use Rector\Core\Rector\AbstractRector; use Rector\DeadCode\ValueObject\PropertyFetchToVariableAssign; use Rector\NodeTypeResolver\Node\AttributeKey; +use Rector\ReadWrite\NodeAnalyzer\ReadExprAnalyzer; use Rector\ReadWrite\NodeFinder\NodeUsageFinder; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -32,7 +33,8 @@ final class RemoveJustPropertyFetchRector extends AbstractRector { public function __construct( - private readonly NodeUsageFinder $nodeUsageFinder + private readonly NodeUsageFinder $nodeUsageFinder, + private readonly ReadExprAnalyzer $readExprAnalyzer ) { } @@ -112,6 +114,10 @@ public function refactor(Node $node): ?Node continue; } + if (! $this->readExprAnalyzer->isExprRead($variableToPropertyAssign->getVariable())) { + continue; + } + $variableUsages = $this->nodeUsageFinder->findVariableUsages( $followingStmts, $variableToPropertyAssign->getVariable()