From c41065174369d76e9dc9b1385a713f984ecc947d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 8 Sep 2025 21:00:11 +0700 Subject: [PATCH 1/2] Avoid reprint on DowngradeReadonlyPropertyRector --- .../Property/DowngradeReadonlyPropertyRector.php | 15 +++------------ .../DowngradeFinalPropertyPromotionRector.php | 6 +++--- .../Fixture/fixture.php.inc | 10 ++++------ 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php b/rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php index 3cd42875..e6e29ac0 100644 --- a/rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php +++ b/rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php @@ -102,17 +102,13 @@ public function refactor(Node $node): ?Node return null; } - $hasChangedDoc = false; $hasChanged = false; foreach ($node->params as $param) { if (! $this->visibilityManipulator->isReadonly($param)) { continue; } - if ($this->addPhpDocTag($param)) { - $hasChangedDoc = true; - } - + $this->addPhpDocTag($param); $this->visibilityManipulator->removeReadonly($param); $hasChanged = true; } @@ -121,23 +117,18 @@ public function refactor(Node $node): ?Node return null; } - if ($hasChangedDoc) { - $node->setAttribute(AttributeKey::ORIGINAL_NODE, null); - } - return $node; } - private function addPhpDocTag(Property|Param $node): bool + private function addPhpDocTag(Property|Param $node): void { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); if ($phpDocInfo->hasByName(self::TAGNAME)) { - return false; + return; } $phpDocInfo->addPhpDocTagNode(new PhpDocTagNode('@' . self::TAGNAME, new GenericTagValueNode(''))); $this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node); - return true; } } diff --git a/rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php b/rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php index c1b5488b..fbdf902f 100644 --- a/rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php +++ b/rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php @@ -110,16 +110,16 @@ public function refactor(Node $node): ?ClassMethod return null; } - private function addPhpDocTag(Property|Param $node): bool + private function addPhpDocTag(Property|Param $node): void { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); if ($phpDocInfo->hasByName(self::TAGNAME)) { - return false; + return; } $phpDocInfo->addPhpDocTagNode(new PhpDocTagNode('@' . self::TAGNAME, new GenericTagValueNode(''))); $this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node); - return true; + return; } } diff --git a/tests/Issues/DowngradeReadonlyClassPropertyToPhp80/Fixture/fixture.php.inc b/tests/Issues/DowngradeReadonlyClassPropertyToPhp80/Fixture/fixture.php.inc index 4d2492d3..87e3bceb 100644 --- a/tests/Issues/DowngradeReadonlyClassPropertyToPhp80/Fixture/fixture.php.inc +++ b/tests/Issues/DowngradeReadonlyClassPropertyToPhp80/Fixture/fixture.php.inc @@ -17,12 +17,10 @@ namespace Rector\Tests\Issues\DowngradeReadonlyClassPropertyToPhp80\Fixture; final class Fixture { - public function __construct( - /** - * @readonly - */ - public array $property - ) + public function __construct(/** + * @readonly + */ + public array $property) { } } From 7da1c10ed3b005d9f81f1696dd4b328957145eae Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 8 Sep 2025 14:02:45 +0000 Subject: [PATCH 2/2] [ci-review] Rector Rectify --- .../Rector/Property/DowngradeReadonlyPropertyRector.php | 1 - .../Rector/Class_/DowngradeFinalPropertyPromotionRector.php | 1 - 2 files changed, 2 deletions(-) diff --git a/rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php b/rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php index e6e29ac0..4396948c 100644 --- a/rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php +++ b/rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php @@ -12,7 +12,6 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Comments\NodeDocBlock\DocBlockUpdater; -use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Privatization\NodeManipulator\VisibilityManipulator; use Rector\Rector\AbstractRector; use Rector\ValueObject\MethodName; diff --git a/rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php b/rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php index fbdf902f..76bb83ac 100644 --- a/rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php +++ b/rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php @@ -120,6 +120,5 @@ private function addPhpDocTag(Property|Param $node): void $phpDocInfo->addPhpDocTagNode(new PhpDocTagNode('@' . self::TAGNAME, new GenericTagValueNode(''))); $this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node); - return; } }