Skip to content

Commit

Permalink
[DeadCode] Skip used as assign var next on RemoveJustPropertyFetchRec…
Browse files Browse the repository at this point in the history
…tor (#3605)

* [DeadCode] Skip used as assign var next on RemoveJustPropertyFetchRector

* Fixed 🎉

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Apr 10, 2023
1 parent 7cc59fe commit 951e9f9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/ReadWrite/NodeFinder/NodeUsageFinder.php
Expand Up @@ -12,6 +12,7 @@
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeNestingScope\NodeFinder\ScopeAwareNodeFinder;
use Rector\NodeTypeResolver\Node\AttributeKey;

final class NodeUsageFinder
{
Expand Down Expand Up @@ -43,7 +44,12 @@ public function findVariableUsages(array $nodes, Variable $variable): array
return false;
}

return $this->nodeNameResolver->isName($node, $variableName);
if (! $this->nodeNameResolver->isName($node, $variableName)) {
return false;
}

$assignedTo = $node->getAttribute(AttributeKey::ASSIGNED_TO);
return ! $assignedTo instanceof Node;
});
}

Expand Down
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

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

final class SkipUsedAsAssignVarNext
{
public function run($arg)
{
$line = $arg->line;
$total = $line->amount;
$arg->line = $line;

return $total;
}
}
6 changes: 3 additions & 3 deletions rules/Removing/Rector/FuncCall/RemoveFuncCallRector.php
Expand Up @@ -74,14 +74,14 @@ public function configure(array $configuration): void
$this->removedFunctions = $configuration;
}

private function removeNodeIfNeeded(Expression $node, FuncCall $expr): void
private function removeNodeIfNeeded(Expression $expression, FuncCall $funcCall): void
{
foreach ($this->removedFunctions as $removedFunction) {
if (! $this->isName($expr->name, $removedFunction)) {
if (! $this->isName($funcCall->name, $removedFunction)) {
continue;
}

$this->removeNode($node);
$this->removeNode($expression);

break;
}
Expand Down

0 comments on commit 951e9f9

Please sign in to comment.