From 232df984614909e49a2a41d3656f9b7855b7d3a7 Mon Sep 17 00:00:00 2001 From: darthf1 Date: Tue, 30 Dec 2025 10:42:56 +0100 Subject: [PATCH 1/3] [DeadCode] Add fixture to keep constructor params with autowire attribute --- .../Fixture/abstract_do.php.inc | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/abstract_do.php.inc diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/abstract_do.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/abstract_do.php.inc new file mode 100644 index 00000000000..87ad28fdedb --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/abstract_do.php.inc @@ -0,0 +1,38 @@ + From 53917713701907f8c8c211e1a9700bad6db32bcb Mon Sep 17 00:00:00 2001 From: darthf1 Date: Tue, 30 Dec 2025 11:20:35 +0100 Subject: [PATCH 2/3] add comment and re-order --- .../Fixture/abstract_do.php.inc | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/abstract_do.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/abstract_do.php.inc index 87ad28fdedb..cd2fa25eb84 100644 --- a/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/abstract_do.php.inc +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/abstract_do.php.inc @@ -10,19 +10,10 @@ use Symfony\Component\DependencyInjection\Attribute\Autowire; namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector\Fixture; -abstract class AbstractDo -{ - public function __construct(private readonly ContainerInterface $filterLocator) - { - } - - abstract protected function doSomething(): void; -} - -namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector\Fixture; - final class DoSomething extends AbstractDo { + # Constructor must be kept if any param has the autowire attribute + # https://symfony.com/doc/current/service_container/autowiring.html public function __construct( #[Autowire(service: 'service_container')] ContainerInterface $filterLocator, @@ -33,6 +24,16 @@ final class DoSomething extends AbstractDo protected function doSomething(): void { } +} + +namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector\Fixture; + +abstract class AbstractDo +{ + public function __construct(private readonly ContainerInterface $filterLocator) + { + } + abstract protected function doSomething(): void; } ?> From 04d081344655144c2bc1c40f14d8e2c1e05ff286 Mon Sep 17 00:00:00 2001 From: darthf1 Date: Tue, 30 Dec 2025 11:47:44 +0100 Subject: [PATCH 3/3] move to Source --- .../{Fixture => Source}/abstract_do.php.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/{Fixture => Source}/abstract_do.php.inc (92%) diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/abstract_do.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Source/abstract_do.php.inc similarity index 92% rename from rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/abstract_do.php.inc rename to rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Source/abstract_do.php.inc index cd2fa25eb84..70fce0e7c13 100644 --- a/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Fixture/abstract_do.php.inc +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector/Source/abstract_do.php.inc @@ -8,7 +8,7 @@ use App\AbstractFilterExtension; use Psr\Container\ContainerInterface; use Symfony\Component\DependencyInjection\Attribute\Autowire; -namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector\Fixture; +namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector\Source; final class DoSomething extends AbstractDo { @@ -26,7 +26,7 @@ final class DoSomething extends AbstractDo } } -namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector\Fixture; +namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector\Source; abstract class AbstractDo {