From 7390870bfe08d6db937a9164c4814fd89cab2537 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 24 Nov 2025 19:01:05 +0700 Subject: [PATCH 1/2] [CodeQuality] Do not replace variable assign on ControllerMethodInjectionToConstructorRector --- .../do_not_replace_variable_assign.php.inc | 38 +++++++++++++++++++ ...llerMethodInjectionToConstructorRector.php | 1 - 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 rules-tests/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector/Fixture/do_not_replace_variable_assign.php.inc diff --git a/rules-tests/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector/Fixture/do_not_replace_variable_assign.php.inc b/rules-tests/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector/Fixture/do_not_replace_variable_assign.php.inc new file mode 100644 index 00000000..b9d72708 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector/Fixture/do_not_replace_variable_assign.php.inc @@ -0,0 +1,38 @@ +modify($logger); + } +} + +?> +----- +modify($this->logger); + } +} + +?> \ No newline at end of file diff --git a/rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php b/rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php index 2b42824b..4c81e24e 100644 --- a/rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php +++ b/rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php @@ -190,7 +190,6 @@ public function refactor(Node $node): ?Node if (! $this->isNames($node, $paramNamesToReplace)) { return null; - } $propertyName = $this->getName($node); From 7bc718560c8dde5f0c94884cb3745846d23dcc52 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 24 Nov 2025 19:05:16 +0700 Subject: [PATCH 2/2] fix --- .../Class_/ControllerMethodInjectionToConstructorRector.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php b/rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php index 4c81e24e..0e7b6bd9 100644 --- a/rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php +++ b/rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php @@ -14,6 +14,7 @@ use PhpParser\Node\Stmt\ClassMethod; use Rector\Doctrine\NodeAnalyzer\AttributeFinder; use Rector\NodeManipulator\ClassDependencyManipulator; +use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PhpParser\Node\Value\ValueResolver; use Rector\PostRector\ValueObject\PropertyMetadata; use Rector\Rector\AbstractRector; @@ -192,6 +193,10 @@ public function refactor(Node $node): ?Node return null; } + if ($node->getAttribute(AttributeKey::IS_BEING_ASSIGNED) === true) { + return null; + } + $propertyName = $this->getName($node); return new PropertyFetch(new Variable('this'), $propertyName); });