Skip to content

Commit 67da1fc

Browse files
committed
[DowngradePhp81] Add @readonly doc on property promotion readonly
1 parent bd39e48 commit 67da1fc

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

rules-tests/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector/Fixture/promoted_property.php.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ namespace Rector\Tests\DowngradePhp81\Rector\Property\DowngradeReadonlyPropertyR
2020
class SomeClass
2121
{
2222
public function __construct(
23+
/**
24+
* @readonly
25+
*/
2326
public string $foo = 'foo'
2427
)
2528
{

rules-tests/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector/Fixture/readonly_implicit_property_promotion.php.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ namespace Rector\Tests\DowngradePhp81\Rector\Property\DowngradeReadonlyPropertyR
2020
class ReadonlyImplicitPropertyPromotion
2121
{
2222
public function __construct(
23+
/**
24+
* @readonly
25+
*/
2326
public string $foo = 'foo'
2427
)
2528
{

rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,22 @@ public function refactor(Node $node): ?Node
8989
return null;
9090
}
9191

92-
if ($node instanceof Property) {
93-
$this->addPhpDocTag($node);
94-
}
92+
$this->addPhpDocTag($node);
9593

9694
$this->visibilityManipulator->removeReadonly($node);
9795

9896
return $node;
9997
}
10098

101-
private function addPhpDocTag(Property $property): void
99+
private function addPhpDocTag(Property|Param $node): void
102100
{
103-
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
101+
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
104102

105103
if ($phpDocInfo->hasByName(self::TAGNAME)) {
106104
return;
107105
}
108106

109107
$phpDocInfo->addPhpDocTagNode(new PhpDocTagNode('@' . self::TAGNAME, new GenericTagValueNode('')));
110-
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($property);
108+
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
111109
}
112110
}

0 commit comments

Comments
 (0)