From 4dee58ba84af36784c9fbf7d8e964363dd15ecc0 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 25 Feb 2022 19:27:26 +0700 Subject: [PATCH] [Php81] Fix property with attribute inlined on ReadOnlyPropertyRector (#1869) --- .../Fixture/with_attribute.php.inc | 43 +++++++++++++++++++ .../Property/ReadOnlyPropertyRector.php | 7 +++ 2 files changed, 50 insertions(+) create mode 100644 rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute.php.inc diff --git a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute.php.inc new file mode 100644 index 00000000000..6ccb2901179 --- /dev/null +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute.php.inc @@ -0,0 +1,43 @@ +name = $name; + } + + public function getName() + { + return $this->name; + } +} + +?> +----- +name = $name; + } + + public function getName() + { + return $this->name; + } +} + +?> diff --git a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php index dcebfd7f016..053e165ed72 100644 --- a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php +++ b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php @@ -12,6 +12,7 @@ use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Core\ValueObject\Visibility; +use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Privatization\NodeManipulator\VisibilityManipulator; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -117,6 +118,12 @@ private function refactorProperty(Property $property): ?Property } $this->visibilityManipulator->makeReadonly($property); + + $attributeGroups = $property->attrGroups; + if ($attributeGroups !== []) { + $property->setAttribute(AttributeKey::ORIGINAL_NODE, null); + } + return $property; }