Skip to content

Commit c410651

Browse files
committed
Avoid reprint on DowngradeReadonlyPropertyRector
1 parent 410a14f commit c410651

File tree

3 files changed

+10
-21
lines changed

3 files changed

+10
-21
lines changed

rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,13 @@ public function refactor(Node $node): ?Node
102102
return null;
103103
}
104104

105-
$hasChangedDoc = false;
106105
$hasChanged = false;
107106
foreach ($node->params as $param) {
108107
if (! $this->visibilityManipulator->isReadonly($param)) {
109108
continue;
110109
}
111110

112-
if ($this->addPhpDocTag($param)) {
113-
$hasChangedDoc = true;
114-
}
115-
111+
$this->addPhpDocTag($param);
116112
$this->visibilityManipulator->removeReadonly($param);
117113
$hasChanged = true;
118114
}
@@ -121,23 +117,18 @@ public function refactor(Node $node): ?Node
121117
return null;
122118
}
123119

124-
if ($hasChangedDoc) {
125-
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
126-
}
127-
128120
return $node;
129121
}
130122

131-
private function addPhpDocTag(Property|Param $node): bool
123+
private function addPhpDocTag(Property|Param $node): void
132124
{
133125
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
134126

135127
if ($phpDocInfo->hasByName(self::TAGNAME)) {
136-
return false;
128+
return;
137129
}
138130

139131
$phpDocInfo->addPhpDocTagNode(new PhpDocTagNode('@' . self::TAGNAME, new GenericTagValueNode('')));
140132
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
141-
return true;
142133
}
143134
}

rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ 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;
123+
return;
124124
}
125125
}

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)