diff --git a/src/NodeManipulator/StmtsManipulator.php b/src/NodeManipulator/StmtsManipulator.php index 11536c87b8..aed0da1811 100644 --- a/src/NodeManipulator/StmtsManipulator.php +++ b/src/NodeManipulator/StmtsManipulator.php @@ -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; @@ -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);