From f55bb409d2d2288881dd11bc56ecf41732ec7554 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 22 Oct 2025 18:36:19 +0700 Subject: [PATCH 1/6] [Php81] Remove usage of AttributeGroupNewLiner on ReadOnlyPropertyRector --- .../Fixture/with_attribute_inline.php.inc | 3 +- .../Fixture/with_attribute_new_line.php.inc | 43 +++++++++++++++++++ .../Property/ReadOnlyPropertyRector.php | 12 +----- 3 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_new_line.php.inc diff --git a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_inline.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_inline.php.inc index b3119f9ce9e..2cf0dfee487 100644 --- a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_inline.php.inc +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_inline.php.inc @@ -25,8 +25,7 @@ namespace Rector\Tests\Php82\Rector\Class_\ReadOnlyClassRector\Fixture; final class WithAttributeInline { - #[Serializer\Since(Option::SINCE_20211124)] - private readonly string $name; + #[Serializer\Since(Option::SINCE_20211124)]private readonly string $name; public function __construct(string $name) { diff --git a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_new_line.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_new_line.php.inc new file mode 100644 index 00000000000..1989b058429 --- /dev/null +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_new_line.php.inc @@ -0,0 +1,43 @@ +name = $name; + } + + public function getName() + { + return $this->name; + } +} + +?> +----- +name = $name; + } + + public function getName() + { + return $this->name; + } +} + +?> diff --git a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php index 49dd58c134a..5e86fdca65b 100644 --- a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php +++ b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php @@ -23,7 +23,6 @@ use Rector\NodeAnalyzer\ParamAnalyzer; use Rector\NodeManipulator\PropertyFetchAssignManipulator; use Rector\NodeManipulator\PropertyManipulator; -use Rector\Php81\NodeManipulator\AttributeGroupNewLiner; use Rector\PhpParser\Node\BetterNodeFinder; use Rector\PHPStan\ScopeFetcher; use Rector\Privatization\NodeManipulator\VisibilityManipulator; @@ -47,8 +46,7 @@ public function __construct( private readonly VisibilityManipulator $visibilityManipulator, private readonly BetterNodeFinder $betterNodeFinder, private readonly PhpDocInfoFactory $phpDocInfoFactory, - private readonly DocBlockUpdater $docBlockUpdater, - private readonly AttributeGroupNewLiner $attributeGroupNewLiner + private readonly DocBlockUpdater $docBlockUpdater ) { } @@ -177,12 +175,6 @@ private function refactorProperty(Class_ $class, Property $property, Scope $scop } $this->visibilityManipulator->makeReadonly($property); - - $attributeGroups = $property->attrGroups; - if ($attributeGroups !== []) { - $this->attributeGroupNewLiner->newLine($this->file, $property); - } - $this->removeReadOnlyDoc($property); return $property; @@ -245,7 +237,7 @@ private function refactorParam(Class_ $class, ClassMethod $classMethod, Param $p } if ($param->attrGroups !== []) { - $this->attributeGroupNewLiner->newLine($this->file, $param); + //$this->attributeGroupNewLiner->newLine($this->file, $param); } $this->visibilityManipulator->makeReadonly($param); From cdabafe8a84498ce9b856c83a7bda3af8dcbd434 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 22 Oct 2025 18:38:00 +0700 Subject: [PATCH 2/6] fix --- rules/Php81/Rector/Property/ReadOnlyPropertyRector.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php index 5e86fdca65b..66c3f6c111f 100644 --- a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php +++ b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php @@ -236,10 +236,6 @@ private function refactorParam(Class_ $class, ClassMethod $classMethod, Param $p return null; } - if ($param->attrGroups !== []) { - //$this->attributeGroupNewLiner->newLine($this->file, $param); - } - $this->visibilityManipulator->makeReadonly($param); $this->removeReadOnlyDoc($param); From 9b6e23ce860ed792ac9362d50b8e04eae14b8b69 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 22 Oct 2025 18:39:42 +0700 Subject: [PATCH 3/6] add fixture inline as is --- ...ibute_on_property_promotion_inline.php.inc | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion_inline.php.inc diff --git a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion_inline.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion_inline.php.inc new file mode 100644 index 00000000000..8adce000d93 --- /dev/null +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion_inline.php.inc @@ -0,0 +1,25 @@ + +----- + From 5e382bba36add91427babc7a8e2dae3a99b3a20c Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 22 Oct 2025 18:40:44 +0700 Subject: [PATCH 4/6] rename fixture --- ... => with_attribute_on_property_promotion_new_line.php.inc} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/{with_attribute_on_property_promotion.php.inc => with_attribute_on_property_promotion_new_line.php.inc} (78%) diff --git a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion_new_line.php.inc similarity index 78% rename from rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion.php.inc rename to rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion_new_line.php.inc index ee208c59a17..1a8128f4dca 100644 --- a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion.php.inc +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion_new_line.php.inc @@ -2,7 +2,7 @@ namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture; -final class WithAttributeOnPropertyPromotion +final class WithAttributeOnPropertyPromotionNewLine { private function __construct( #[MyAttr] @@ -16,7 +16,7 @@ final class WithAttributeOnPropertyPromotion namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture; -final class WithAttributeOnPropertyPromotion +final class WithAttributeOnPropertyPromotionNewLine { private function __construct( #[MyAttr] From a8760c963ce70952377e0730369b0cf8e8f3612b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 22 Oct 2025 18:43:05 +0700 Subject: [PATCH 5/6] fix phpstan --- rules/Php81/NodeManipulator/AttributeGroupNewLiner.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php index 93a0eccaf41..2fe6ab63e3f 100644 --- a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php +++ b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php @@ -6,14 +6,15 @@ use PhpParser\Node; use PhpParser\Node\AttributeGroup; +use PhpParser\Node\Stmt\Class_; use Rector\ValueObject\Application\File; use Webmozart\Assert\Assert; final class AttributeGroupNewLiner { - public function newLine(File $file, Node $node): void + public function newLine(File $file, Class_ $node): void { - $attrGroups = $node->attrGroups ?? []; + $attrGroups = $node->attrGroups; if ($attrGroups === []) { return; From fd6908862fe082afc803a59b860bdd0487dc4154 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 22 Oct 2025 11:46:04 +0000 Subject: [PATCH 6/6] [ci-review] Rector Rectify --- rules/Php81/NodeManipulator/AttributeGroupNewLiner.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php index 2fe6ab63e3f..9d0c41bc9ee 100644 --- a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php +++ b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php @@ -4,7 +4,6 @@ namespace Rector\Php81\NodeManipulator; -use PhpParser\Node; use PhpParser\Node\AttributeGroup; use PhpParser\Node\Stmt\Class_; use Rector\ValueObject\Application\File; @@ -12,9 +11,9 @@ final class AttributeGroupNewLiner { - public function newLine(File $file, Class_ $node): void + public function newLine(File $file, Class_ $class): void { - $attrGroups = $node->attrGroups; + $attrGroups = $class->attrGroups; if ($attrGroups === []) { return; @@ -24,7 +23,7 @@ public function newLine(File $file, Class_ $node): void Assert::isArray($attrGroups); $oldTokens = $file->getOldTokens(); - $startTokenPos = $node->getStartTokenPos(); + $startTokenPos = $class->getStartTokenPos(); if (! isset($oldTokens[$startTokenPos])) { return;