Skip to content

Commit

Permalink
[Php81] Handle with attribute on ReadOnlyPropertyRector on property …
Browse files Browse the repository at this point in the history
…promotion (#5692)

* [Php81] Handle with attribute on ReadOnlyPropertyRector

* [Php81] Handle with attribute on ReadOnlyPropertyRector
  • Loading branch information
samsonasik committed Mar 5, 2024
1 parent 104f656 commit e29b97e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture;

final class WithAttributeOnPropertyPromotion
{
private function __construct(
#[MyAttr]
private string $id
){}
}

?>
-----
<?php

namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture;

final class WithAttributeOnPropertyPromotion
{
private function __construct(
#[MyAttr]
private readonly string $id
){}
}

?>
4 changes: 4 additions & 0 deletions rules/Php81/Rector/Property/ReadOnlyPropertyRector.php
Expand Up @@ -200,6 +200,10 @@ private function refactorParam(Class_ $class, ClassMethod $classMethod, Param $p
return null;
}

if ($param->attrGroups !== []) {
$param->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}

$this->visibilityManipulator->makeReadonly($param);
return $param;
}
Expand Down

0 comments on commit e29b97e

Please sign in to comment.