Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


public function __construct(string $name)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Rector\Tests\Php82\Rector\Class_\ReadOnlyClassRector\Fixture;

final class WithAttributeNewLine
{
#[Serializer\Since(Option::SINCE_20211124)]
private string $name;

public function __construct(string $name)
{
$this->name = $name;
}

public function getName()
{
return $this->name;
}
}

?>
-----
<?php

namespace Rector\Tests\Php82\Rector\Class_\ReadOnlyClassRector\Fixture;

final class WithAttributeNewLine
{
#[Serializer\Since(Option::SINCE_20211124)]
private readonly string $name;

public function __construct(string $name)
{
$this->name = $name;
}

public function getName()
{
return $this->name;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

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

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

?>
-----
<?php

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

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

?>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

final class WithAttributeOnPropertyPromotion
final class WithAttributeOnPropertyPromotionNewLine
{
private function __construct(
#[MyAttr]
Expand All @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions rules/Php81/NodeManipulator/AttributeGroupNewLiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 1 addition & 13 deletions rules/Php81/Rector/Property/ReadOnlyPropertyRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down