diff --git a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_inline.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_inline.php.inc index b3119f9ce9e..2cf0dfee487 100644 --- a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_inline.php.inc +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_inline.php.inc @@ -25,8 +25,7 @@ namespace Rector\Tests\Php82\Rector\Class_\ReadOnlyClassRector\Fixture; final class WithAttributeInline { - #[Serializer\Since(Option::SINCE_20211124)] - private readonly string $name; + #[Serializer\Since(Option::SINCE_20211124)]private readonly string $name; public function __construct(string $name) { diff --git a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_new_line.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_new_line.php.inc new file mode 100644 index 00000000000..1989b058429 --- /dev/null +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_new_line.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-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion_inline.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion_inline.php.inc new file mode 100644 index 00000000000..8adce000d93 --- /dev/null +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion_inline.php.inc @@ -0,0 +1,25 @@ + +----- + diff --git a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion_new_line.php.inc similarity index 78% rename from rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion.php.inc rename to rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion_new_line.php.inc index ee208c59a17..1a8128f4dca 100644 --- a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion.php.inc +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/with_attribute_on_property_promotion_new_line.php.inc @@ -2,7 +2,7 @@ namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture; -final class WithAttributeOnPropertyPromotion +final class WithAttributeOnPropertyPromotionNewLine { private function __construct( #[MyAttr] @@ -16,7 +16,7 @@ final class WithAttributeOnPropertyPromotion namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture; -final class WithAttributeOnPropertyPromotion +final class WithAttributeOnPropertyPromotionNewLine { private function __construct( #[MyAttr] diff --git a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php index 93a0eccaf41..9d0c41bc9ee 100644 --- a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php +++ b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php @@ -4,16 +4,16 @@ namespace Rector\Php81\NodeManipulator; -use PhpParser\Node; use PhpParser\Node\AttributeGroup; +use PhpParser\Node\Stmt\Class_; use Rector\ValueObject\Application\File; use Webmozart\Assert\Assert; final class AttributeGroupNewLiner { - public function newLine(File $file, Node $node): void + public function newLine(File $file, Class_ $class): void { - $attrGroups = $node->attrGroups ?? []; + $attrGroups = $class->attrGroups; if ($attrGroups === []) { return; @@ -23,7 +23,7 @@ public function newLine(File $file, Node $node): void Assert::isArray($attrGroups); $oldTokens = $file->getOldTokens(); - $startTokenPos = $node->getStartTokenPos(); + $startTokenPos = $class->getStartTokenPos(); if (! isset($oldTokens[$startTokenPos])) { return; diff --git a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php index 49dd58c134a..66c3f6c111f 100644 --- a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php +++ b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php @@ -23,7 +23,6 @@ use Rector\NodeAnalyzer\ParamAnalyzer; use Rector\NodeManipulator\PropertyFetchAssignManipulator; use Rector\NodeManipulator\PropertyManipulator; -use Rector\Php81\NodeManipulator\AttributeGroupNewLiner; use Rector\PhpParser\Node\BetterNodeFinder; use Rector\PHPStan\ScopeFetcher; use Rector\Privatization\NodeManipulator\VisibilityManipulator; @@ -47,8 +46,7 @@ public function __construct( private readonly VisibilityManipulator $visibilityManipulator, private readonly BetterNodeFinder $betterNodeFinder, private readonly PhpDocInfoFactory $phpDocInfoFactory, - private readonly DocBlockUpdater $docBlockUpdater, - private readonly AttributeGroupNewLiner $attributeGroupNewLiner + private readonly DocBlockUpdater $docBlockUpdater ) { } @@ -177,12 +175,6 @@ private function refactorProperty(Class_ $class, Property $property, Scope $scop } $this->visibilityManipulator->makeReadonly($property); - - $attributeGroups = $property->attrGroups; - if ($attributeGroups !== []) { - $this->attributeGroupNewLiner->newLine($this->file, $property); - } - $this->removeReadOnlyDoc($property); return $property; @@ -244,10 +236,6 @@ private function refactorParam(Class_ $class, ClassMethod $classMethod, Param $p return null; } - if ($param->attrGroups !== []) { - $this->attributeGroupNewLiner->newLine($this->file, $param); - } - $this->visibilityManipulator->makeReadonly($param); $this->removeReadOnlyDoc($param);