Skip to content

Commit 1656e40

Browse files
Avoid reprint whole ClassMethod on DowngradeReadonlyPropertyRector (#325)
* Avoid reprint on DowngradeReadonlyPropertyRector * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <[email protected]>
1 parent 410a14f commit 1656e40

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
1313
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
1414
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
15-
use Rector\NodeTypeResolver\Node\AttributeKey;
1615
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
1716
use Rector\Rector\AbstractRector;
1817
use Rector\ValueObject\MethodName;
@@ -102,17 +101,13 @@ public function refactor(Node $node): ?Node
102101
return null;
103102
}
104103

105-
$hasChangedDoc = false;
106104
$hasChanged = false;
107105
foreach ($node->params as $param) {
108106
if (! $this->visibilityManipulator->isReadonly($param)) {
109107
continue;
110108
}
111109

112-
if ($this->addPhpDocTag($param)) {
113-
$hasChangedDoc = true;
114-
}
115-
110+
$this->addPhpDocTag($param);
116111
$this->visibilityManipulator->removeReadonly($param);
117112
$hasChanged = true;
118113
}
@@ -121,23 +116,18 @@ public function refactor(Node $node): ?Node
121116
return null;
122117
}
123118

124-
if ($hasChangedDoc) {
125-
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
126-
}
127-
128119
return $node;
129120
}
130121

131-
private function addPhpDocTag(Property|Param $node): bool
122+
private function addPhpDocTag(Property|Param $node): void
132123
{
133124
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
134125

135126
if ($phpDocInfo->hasByName(self::TAGNAME)) {
136-
return false;
127+
return;
137128
}
138129

139130
$phpDocInfo->addPhpDocTagNode(new PhpDocTagNode('@' . self::TAGNAME, new GenericTagValueNode('')));
140131
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
141-
return true;
142132
}
143133
}

rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,15 @@ public function refactor(Node $node): ?ClassMethod
110110
return null;
111111
}
112112

113-
private function addPhpDocTag(Property|Param $node): bool
113+
private function addPhpDocTag(Property|Param $node): void
114114
{
115115
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
116116

117117
if ($phpDocInfo->hasByName(self::TAGNAME)) {
118-
return false;
118+
return;
119119
}
120120

121121
$phpDocInfo->addPhpDocTagNode(new PhpDocTagNode('@' . self::TAGNAME, new GenericTagValueNode('')));
122122
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
123-
return true;
124123
}
125124
}

tests/Issues/DowngradeReadonlyClassPropertyToPhp80/Fixture/fixture.php.inc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ namespace Rector\Tests\Issues\DowngradeReadonlyClassPropertyToPhp80\Fixture;
1717

1818
final class Fixture
1919
{
20-
public function __construct(
21-
/**
22-
* @readonly
23-
*/
24-
public array $property
25-
)
20+
public function __construct(/**
21+
* @readonly
22+
*/
23+
public array $property)
2624
{
2725
}
2826
}

0 commit comments

Comments
 (0)