Skip to content

Commit

Permalink
skip next array dim fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jul 3, 2022
1 parent 0637894 commit 7c5108c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

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

final class SkipArrayDimFetch
{
private int $temporaryValue;

public function run()
{
$result = 100;

$this->temporaryValue[] = $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\DeadCode\Rector\StmtsAwareInterface;

use PhpParser\Node;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Variable;
Expand Down Expand Up @@ -103,6 +104,11 @@ public function refactor(Node $node): ?Node

$nextAssign = $nextStmt->expr;

// too complex
if ($nextAssign->var instanceof ArrayDimFetch) {
continue;
}

if (! $this->areTwoVariablesCrossAssign($currentAssign, $nextAssign)) {
continue;
}
Expand Down

0 comments on commit 7c5108c

Please sign in to comment.