From d257e68fbf860d1bf3a07ea10cb40551bd95056c Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 18 Dec 2024 09:37:57 +0000 Subject: [PATCH] Updated Rector to commit e7e8c5bfac8df0f605d6588c3612a05cca74b017 https://github.com/rectorphp/rector-src/commit/e7e8c5bfac8df0f605d6588c3612a05cca74b017 [DeadCode] Skip key variable used in throw stmts in catch on RemoveUnusedForeachKeyRector (#6606) --- src/Application/VersionResolver.php | 4 ++-- src/NodeManipulator/StmtsManipulator.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 34ccadf2665..49f459735cd 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'd2298c6fd6fb233e4fcec5d3b69cd2eed52910e6'; + public const PACKAGE_VERSION = 'e7e8c5bfac8df0f605d6588c3612a05cca74b017'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-12-18 13:44:24'; + public const RELEASE_DATE = '2024-12-18 16:35:21'; /** * @var int */ diff --git a/src/NodeManipulator/StmtsManipulator.php b/src/NodeManipulator/StmtsManipulator.php index 93ecc2b5b01..3a1e39d691b 100644 --- a/src/NodeManipulator/StmtsManipulator.php +++ b/src/NodeManipulator/StmtsManipulator.php @@ -9,6 +9,8 @@ use PhpParser\Node\Expr\Variable; 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; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -83,6 +85,12 @@ final class StmtsManipulator return \false; } $stmts = \array_slice($stmtsAware instanceof StmtsAwareInterface ? $stmtsAware->stmts : $stmtsAware, $jumpToKey, null, \true); + if ($stmtsAware instanceof TryCatch) { + $stmts = \array_merge($stmts, $stmtsAware->catches); + if ($stmtsAware->finally instanceof Finally_) { + $stmts = \array_merge($stmts, $stmtsAware->finally->stmts); + } + } $variable = new Variable($variableName); return (bool) $this->betterNodeFinder->findFirst($stmts, fn(Node $subNode): bool => $this->exprUsedInNodeAnalyzer->isUsed($subNode, $variable)); }