Skip to content

Commit

Permalink
[DeadCode] Skip append array data on RemoveJustPropertyFetchRector (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Dec 14, 2022
1 parent be3bdd0 commit e71df1b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Rector\Tests\DeadCode\Rector\StmtsAwareInterface\RemoveJustPropertyFetchRector\Fixture;

final class SkipAppendArrayData
{
private $default = ['some data'];

public function run()
{
$where = $this->default;
$where[] = 'some append data';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,7 +33,8 @@
final class RemoveJustPropertyFetchRector extends AbstractRector
{
public function __construct(
private readonly NodeUsageFinder $nodeUsageFinder
private readonly NodeUsageFinder $nodeUsageFinder,
private readonly ReadExprAnalyzer $readExprAnalyzer
) {
}

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e71df1b

Please sign in to comment.