From 063bcecdb94f7ace1dffa5082b5458515fa4d40a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 2 Jan 2026 07:52:46 +0700 Subject: [PATCH 1/3] [DeadCode] Add Declare_ to NodeGroup::STMTS_AWARE to allow remove Declare_ stmts --- .../Fixture/on_ticks.php.inc | 25 +++++++++++++++++++ src/Application/NodeAttributeReIndexer.php | 3 +-- src/PhpParser/Enum/NodeGroup.php | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 rules-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/on_ticks.php.inc diff --git a/rules-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/on_ticks.php.inc b/rules-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/on_ticks.php.inc new file mode 100644 index 00000000000..f676ffdc229 --- /dev/null +++ b/rules-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/on_ticks.php.inc @@ -0,0 +1,25 @@ + +----- + diff --git a/src/Application/NodeAttributeReIndexer.php b/src/Application/NodeAttributeReIndexer.php index bdc581266bf..66eb86a3f2b 100644 --- a/src/Application/NodeAttributeReIndexer.php +++ b/src/Application/NodeAttributeReIndexer.php @@ -15,7 +15,6 @@ use PhpParser\Node\FunctionLike; use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; -use PhpParser\Node\Stmt\Declare_; use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\If_; use PhpParser\Node\Stmt\Switch_; @@ -66,7 +65,7 @@ public static function reIndexNodeAttributes(Node $node): ?Node private static function reIndexStmtsKeys(Node $node): ?Node { - if (! NodeGroup::isStmtAwareNode($node) && ! $node instanceof ClassLike && ! $node instanceof Declare_) { + if (! NodeGroup::isStmtAwareNode($node) && ! $node instanceof ClassLike) { return null; } diff --git a/src/PhpParser/Enum/NodeGroup.php b/src/PhpParser/Enum/NodeGroup.php index c3ab3264de8..0b109437487 100644 --- a/src/PhpParser/Enum/NodeGroup.php +++ b/src/PhpParser/Enum/NodeGroup.php @@ -12,6 +12,7 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassConst; use PhpParser\Node\Stmt\ClassMethod; +use PhpParser\Node\Stmt\Declare_; use PhpParser\Node\Stmt\Do_; use PhpParser\Node\Stmt\Else_; use PhpParser\Node\Stmt\ElseIf_; @@ -56,6 +57,7 @@ final class NodeGroup TryCatch::class, While_::class, FileNode::class, + Declare_::class, ]; /** From 11f2d7f2dfc2b6ef258445d2e6fc13dbcfa10d80 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 2 Jan 2026 07:54:21 +0700 Subject: [PATCH 2/3] [DeadCode] Add Declare_ to NodeGroup::STMTS_AWARE to allow remove Declare_ stmts --- .../RemoveUnreachableStatementRector/Fixture/on_ticks.php.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/on_ticks.php.inc b/rules-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/on_ticks.php.inc index f676ffdc229..ae5b553804e 100644 --- a/rules-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/on_ticks.php.inc +++ b/rules-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/on_ticks.php.inc @@ -5,7 +5,7 @@ namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fix declare(ticks=1) { echo 'test'; - die; + throw new \Exception(); echo 'unreachable'; } @@ -19,7 +19,7 @@ namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fix declare(ticks=1) { echo 'test'; - die; + throw new \Exception(); } ?> From 743c91787734bd4e75349013882b1f321e9a4a32 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 2 Jan 2026 08:43:13 +0700 Subject: [PATCH 3/3] final touch: add to phpstan alias --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index be9ef0658dc..d619aa2887d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -10,7 +10,7 @@ parameters: # see https://phpstan.org/writing-php-code/phpdoc-types#global-type-aliases typeAliases: - StmtsAware: \PhpParser\Node\Stmt\Block | \PhpParser\Node\Expr\Closure | \PhpParser\Node\Stmt\Case_ | \PhpParser\Node\Stmt\Catch_ | \PhpParser\Node\Stmt\ClassMethod | \PhpParser\Node\Stmt\Do_ | \PhpParser\Node\Stmt\Else_ | \PhpParser\Node\Stmt\ElseIf_ | \PhpParser\Node\Stmt\Finally_ | \PhpParser\Node\Stmt\For_ | \PhpParser\Node\Stmt\Foreach_ | \PhpParser\Node\Stmt\Function_ | \PhpParser\Node\Stmt\If_ | \PhpParser\Node\Stmt\Namespace_ | \PhpParser\Node\Stmt\TryCatch | \PhpParser\Node\Stmt\While_ | \Rector\PhpParser\Node\FileNode + StmtsAware: \PhpParser\Node\Stmt\Block | \PhpParser\Node\Expr\Closure | \PhpParser\Node\Stmt\Case_ | \PhpParser\Node\Stmt\Catch_ | \PhpParser\Node\Stmt\ClassMethod | \PhpParser\Node\Stmt\Do_ | \PhpParser\Node\Stmt\Else_ | \PhpParser\Node\Stmt\ElseIf_ | \PhpParser\Node\Stmt\Finally_ | \PhpParser\Node\Stmt\For_ | \PhpParser\Node\Stmt\Foreach_ | \PhpParser\Node\Stmt\Function_ | \PhpParser\Node\Stmt\If_ | \PhpParser\Node\Stmt\Namespace_ | \PhpParser\Node\Stmt\TryCatch | \PhpParser\Node\Stmt\While_ | \Rector\PhpParser\Node\FileNode | \PhpParser\Node\Stmt\Declare_ # requires exact closure types checkMissingCallableSignature: true