Skip to content

Commit

Permalink
[DeadCode] Skip key variable used in throw stmts in catch on RemoveUn…
Browse files Browse the repository at this point in the history
…usedForeachKeyRector
  • Loading branch information
samsonasik committed Dec 18, 2024
1 parent 3baf881 commit 6eda64b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/NodeManipulator/StmtsManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Finally_;
use PhpParser\Node\Stmt\TryCatch;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\DeadCode\NodeAnalyzer\ExprUsedInNodeAnalyzer;
Expand Down Expand Up @@ -96,6 +97,10 @@ public function isVariableUsedInNextStmt(
$stmts,
$stmtsAware->catches
);

if ($stmtsAware->finally instanceof Finally_) {
$stmts = array_merge($stmts, $stmtsAware->finally->stmts);
}
}

$variable = new Variable($variableName);
Expand Down

0 comments on commit 6eda64b

Please sign in to comment.