From 6972a3a67219d986ee85e3421cbd5839f68f64ca Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 5 Jan 2026 19:42:45 +0700 Subject: [PATCH 1/4] [DeadCode] Skip final and non-public __construct() on RemoveParentDelegatingConstructorRector --- .../Fixture/skip_final_construct.php.inc | 13 +++++++++++++ .../Fixture/skip_private_construct.php.inc | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/skip_final_construct.php.inc create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/skip_private_construct.php.inc diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/skip_final_construct.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/skip_final_construct.php.inc new file mode 100644 index 00000000000..1b070c04436 --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/skip_final_construct.php.inc @@ -0,0 +1,13 @@ + Date: Mon, 5 Jan 2026 19:43:30 +0700 Subject: [PATCH 2/4] skip final --- .../ClassMethod/RemoveParentDelegatingConstructorRector.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rules/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector.php b/rules/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector.php index a767513b730..e781a1a2eb9 100644 --- a/rules/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector.php +++ b/rules/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector.php @@ -98,6 +98,10 @@ public function refactor(Node $node): ?int return null; } + if ($node->isFinal()) { + return null; + } + $parentMethodReflection = $this->matchParentConstructorReflection($node); if (! $parentMethodReflection instanceof ExtendedMethodReflection) { return null; From 305d1bb894211c40fecd8494e1e5cb3660b093cb Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 5 Jan 2026 19:43:46 +0700 Subject: [PATCH 3/4] skip non-public --- .../ClassMethod/RemoveParentDelegatingConstructorRector.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rules/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector.php b/rules/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector.php index e781a1a2eb9..758b2e92d29 100644 --- a/rules/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector.php +++ b/rules/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector.php @@ -102,6 +102,10 @@ public function refactor(Node $node): ?int return null; } + if (! $node->isPublic()) { + return null; + } + $parentMethodReflection = $this->matchParentConstructorReflection($node); if (! $parentMethodReflection instanceof ExtendedMethodReflection) { return null; From 7b758580319d6615fdef38d120becbeee28d5020 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 5 Jan 2026 19:47:11 +0700 Subject: [PATCH 4/4] final touch: better demo fixxture --- .../Fixture/skip_private_construct.php.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/skip_private_construct.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/skip_private_construct.php.inc index 928d2f9cbc5..c64556a7013 100644 --- a/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/skip_private_construct.php.inc +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/skip_private_construct.php.inc @@ -11,7 +11,7 @@ final class SkipPrivateConstruct extends String_ parent::__construct($value, $attributes); } - public function create($value, $attributes) + public static function create($value, $attributes) { return new self($value, $attributes); }