From 2094baa060c066b922d9fb7ea3a59bcdd4629f6f Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 22 Oct 2025 00:51:19 +0200 Subject: [PATCH 1/2] remove AttributeGroupNewLiner as fixed in php-parser 5.6.2 --- rector.php | 1 - ...ropertyVisibilityOnReadonlyClassRector.php | 12 +----------- .../Property/ReadOnlyPropertyRector.php | 13 +------------ .../ReadonlyClassManipulator.php | 19 ++----------------- .../Rector/Class_/ReadOnlyClassRector.php | 2 +- .../Class_/ReadOnlyAnonymousClassRector.php | 2 +- .../Class_/FinalizeTestCaseClassRector.php | 8 +------- 7 files changed, 7 insertions(+), 50 deletions(-) diff --git a/rector.php b/rector.php index b24f7fe82f0..0d81cf84a09 100644 --- a/rector.php +++ b/rector.php @@ -18,7 +18,6 @@ naming: true, instanceOf: true, earlyReturn: true, - strictBooleans: true, rectorPreset: true, phpunitCodeQuality: true ) diff --git a/rules/CodeQuality/Rector/Class_/RemoveReadonlyPropertyVisibilityOnReadonlyClassRector.php b/rules/CodeQuality/Rector/Class_/RemoveReadonlyPropertyVisibilityOnReadonlyClassRector.php index e1bf1ed8e6a..5bfa5aca8a5 100644 --- a/rules/CodeQuality/Rector/Class_/RemoveReadonlyPropertyVisibilityOnReadonlyClassRector.php +++ b/rules/CodeQuality/Rector/Class_/RemoveReadonlyPropertyVisibilityOnReadonlyClassRector.php @@ -7,7 +7,6 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; -use Rector\Php81\NodeManipulator\AttributeGroupNewLiner; use Rector\Privatization\NodeManipulator\VisibilityManipulator; use Rector\Rector\AbstractRector; use Rector\ValueObject\MethodName; @@ -22,8 +21,7 @@ final class RemoveReadonlyPropertyVisibilityOnReadonlyClassRector extends AbstractRector implements MinPhpVersionInterface { public function __construct( - private readonly VisibilityManipulator $visibilityManipulator, - private readonly AttributeGroupNewLiner $attributeGroupNewLiner + private readonly VisibilityManipulator $visibilityManipulator ) { } @@ -87,10 +85,6 @@ public function refactor(Node $node): ?Node $this->visibilityManipulator->removeReadonly($param); $hasChanged = true; - - if ($param->attrGroups !== []) { - $this->attributeGroupNewLiner->newLine($this->file, $param); - } } } @@ -101,10 +95,6 @@ public function refactor(Node $node): ?Node $this->visibilityManipulator->removeReadonly($property); $hasChanged = true; - - if ($property->attrGroups !== []) { - $this->attributeGroupNewLiner->newLine($this->file, $property); - } } if (! $hasChanged) { diff --git a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php index 49dd58c134a..7aa9e4a4320 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 ) { } @@ -178,11 +176,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 +237,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); diff --git a/rules/Php82/NodeManipulator/ReadonlyClassManipulator.php b/rules/Php82/NodeManipulator/ReadonlyClassManipulator.php index b28f3b74a2b..a24ee847841 100644 --- a/rules/Php82/NodeManipulator/ReadonlyClassManipulator.php +++ b/rules/Php82/NodeManipulator/ReadonlyClassManipulator.php @@ -15,10 +15,8 @@ use PHPStan\Reflection\ReflectionProvider; use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; use Rector\Php81\Enum\AttributeName; -use Rector\Php81\NodeManipulator\AttributeGroupNewLiner; use Rector\PHPStan\ScopeFetcher; use Rector\Privatization\NodeManipulator\VisibilityManipulator; -use Rector\ValueObject\Application\File; use Rector\ValueObject\MethodName; use Rector\ValueObject\Visibility; @@ -27,12 +25,11 @@ public function __construct( private VisibilityManipulator $visibilityManipulator, private PhpAttributeAnalyzer $phpAttributeAnalyzer, - private ReflectionProvider $reflectionProvider, - private AttributeGroupNewLiner $attributeGroupNewLiner + private ReflectionProvider $reflectionProvider ) { } - public function process(Class_ $class, File $file): Class_|null + public function process(Class_ $class): Class_|null { $scope = ScopeFetcher::fetch($class); if ($this->shouldSkip($class, $scope)) { @@ -46,23 +43,11 @@ public function process(Class_ $class, File $file): Class_|null if ($constructClassMethod instanceof ClassMethod) { foreach ($constructClassMethod->getParams() as $param) { $this->visibilityManipulator->removeReadonly($param); - - if ($param->attrGroups !== []) { - $this->attributeGroupNewLiner->newLine($file, $param); - } } } foreach ($class->getProperties() as $property) { $this->visibilityManipulator->removeReadonly($property); - - if ($property->attrGroups !== []) { - $this->attributeGroupNewLiner->newLine($file, $property); - } - } - - if ($class->attrGroups !== []) { - $this->attributeGroupNewLiner->newLine($file, $class); } return $class; diff --git a/rules/Php82/Rector/Class_/ReadOnlyClassRector.php b/rules/Php82/Rector/Class_/ReadOnlyClassRector.php index 41b58be53a7..8aad77813c9 100644 --- a/rules/Php82/Rector/Class_/ReadOnlyClassRector.php +++ b/rules/Php82/Rector/Class_/ReadOnlyClassRector.php @@ -68,7 +68,7 @@ public function refactor(Node $node): ?Node return null; } - return $this->readonlyClassManipulator->process($node, $this->file); + return $this->readonlyClassManipulator->process($node); } public function provideMinPhpVersion(): int diff --git a/rules/Php83/Rector/Class_/ReadOnlyAnonymousClassRector.php b/rules/Php83/Rector/Class_/ReadOnlyAnonymousClassRector.php index a64bff2986e..f3ac0a0cdd9 100644 --- a/rules/Php83/Rector/Class_/ReadOnlyAnonymousClassRector.php +++ b/rules/Php83/Rector/Class_/ReadOnlyAnonymousClassRector.php @@ -68,7 +68,7 @@ public function refactor(Node $node): ?Node return null; } - return $this->readonlyClassManipulator->process($node, $this->file); + return $this->readonlyClassManipulator->process($node); } public function provideMinPhpVersion(): int diff --git a/rules/Privatization/Rector/Class_/FinalizeTestCaseClassRector.php b/rules/Privatization/Rector/Class_/FinalizeTestCaseClassRector.php index ab709b7feb1..0a8db64329d 100644 --- a/rules/Privatization/Rector/Class_/FinalizeTestCaseClassRector.php +++ b/rules/Privatization/Rector/Class_/FinalizeTestCaseClassRector.php @@ -7,7 +7,6 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Class_; use PHPStan\Reflection\ReflectionProvider; -use Rector\Php81\NodeManipulator\AttributeGroupNewLiner; use Rector\Privatization\NodeManipulator\VisibilityManipulator; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -20,8 +19,7 @@ final class FinalizeTestCaseClassRector extends AbstractRector { public function __construct( private readonly ReflectionProvider $reflectionProvider, - private readonly VisibilityManipulator $visibilityManipulator, - private readonly AttributeGroupNewLiner $attributeGroupNewLiner + private readonly VisibilityManipulator $visibilityManipulator ) { } @@ -85,10 +83,6 @@ public function refactor(Node $node): ?Node return null; } - if ($node->attrGroups !== []) { - $this->attributeGroupNewLiner->newLine($this->file, $node); - } - $this->visibilityManipulator->makeFinal($node); return $node; From 289b4d0de4a901c6372a810c8cf96d419cd5a603 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 22 Oct 2025 00:53:41 +0200 Subject: [PATCH 2/2] restore --- .../do_not_remove_parameter_attribute.php.inc | 2 +- ...ropertyVisibilityOnReadonlyClassRector.php | 12 +++++++++- .../Property/ReadOnlyPropertyRector.php | 13 ++++++++++- .../ReadonlyClassManipulator.php | 23 +++++++++++++++---- .../Rector/Class_/ReadOnlyClassRector.php | 2 +- 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/do_not_remove_parameter_attribute.php.inc b/rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/do_not_remove_parameter_attribute.php.inc index dfb36b5303a..ddf318dcaaf 100644 --- a/rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/do_not_remove_parameter_attribute.php.inc +++ b/rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/do_not_remove_parameter_attribute.php.inc @@ -25,7 +25,7 @@ namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromo final class DoNotRemoveParameterAttribute { public function __construct( - #[\SensitiveParameter]private string $password + #[\SensitiveParameter] private string $password ) { } diff --git a/rules/CodeQuality/Rector/Class_/RemoveReadonlyPropertyVisibilityOnReadonlyClassRector.php b/rules/CodeQuality/Rector/Class_/RemoveReadonlyPropertyVisibilityOnReadonlyClassRector.php index 5bfa5aca8a5..e1bf1ed8e6a 100644 --- a/rules/CodeQuality/Rector/Class_/RemoveReadonlyPropertyVisibilityOnReadonlyClassRector.php +++ b/rules/CodeQuality/Rector/Class_/RemoveReadonlyPropertyVisibilityOnReadonlyClassRector.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; +use Rector\Php81\NodeManipulator\AttributeGroupNewLiner; use Rector\Privatization\NodeManipulator\VisibilityManipulator; use Rector\Rector\AbstractRector; use Rector\ValueObject\MethodName; @@ -21,7 +22,8 @@ final class RemoveReadonlyPropertyVisibilityOnReadonlyClassRector extends AbstractRector implements MinPhpVersionInterface { public function __construct( - private readonly VisibilityManipulator $visibilityManipulator + private readonly VisibilityManipulator $visibilityManipulator, + private readonly AttributeGroupNewLiner $attributeGroupNewLiner ) { } @@ -85,6 +87,10 @@ public function refactor(Node $node): ?Node $this->visibilityManipulator->removeReadonly($param); $hasChanged = true; + + if ($param->attrGroups !== []) { + $this->attributeGroupNewLiner->newLine($this->file, $param); + } } } @@ -95,6 +101,10 @@ public function refactor(Node $node): ?Node $this->visibilityManipulator->removeReadonly($property); $hasChanged = true; + + if ($property->attrGroups !== []) { + $this->attributeGroupNewLiner->newLine($this->file, $property); + } } if (! $hasChanged) { diff --git a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php index 7aa9e4a4320..49dd58c134a 100644 --- a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php +++ b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php @@ -23,6 +23,7 @@ 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; @@ -46,7 +47,8 @@ public function __construct( private readonly VisibilityManipulator $visibilityManipulator, private readonly BetterNodeFinder $betterNodeFinder, private readonly PhpDocInfoFactory $phpDocInfoFactory, - private readonly DocBlockUpdater $docBlockUpdater + private readonly DocBlockUpdater $docBlockUpdater, + private readonly AttributeGroupNewLiner $attributeGroupNewLiner ) { } @@ -176,6 +178,11 @@ 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; @@ -237,6 +244,10 @@ 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); diff --git a/rules/Php82/NodeManipulator/ReadonlyClassManipulator.php b/rules/Php82/NodeManipulator/ReadonlyClassManipulator.php index a24ee847841..2a56ca4aacb 100644 --- a/rules/Php82/NodeManipulator/ReadonlyClassManipulator.php +++ b/rules/Php82/NodeManipulator/ReadonlyClassManipulator.php @@ -15,8 +15,10 @@ use PHPStan\Reflection\ReflectionProvider; use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; use Rector\Php81\Enum\AttributeName; +use Rector\Php81\NodeManipulator\AttributeGroupNewLiner; use Rector\PHPStan\ScopeFetcher; use Rector\Privatization\NodeManipulator\VisibilityManipulator; +use Rector\ValueObject\Application\File; use Rector\ValueObject\MethodName; use Rector\ValueObject\Visibility; @@ -25,11 +27,12 @@ public function __construct( private VisibilityManipulator $visibilityManipulator, private PhpAttributeAnalyzer $phpAttributeAnalyzer, - private ReflectionProvider $reflectionProvider + private ReflectionProvider $reflectionProvider, + private AttributeGroupNewLiner $attributeGroupNewLiner ) { } - public function process(Class_ $class): Class_|null + public function process(Class_ $class, File $file): Class_|null { $scope = ScopeFetcher::fetch($class); if ($this->shouldSkip($class, $scope)) { @@ -43,11 +46,23 @@ public function process(Class_ $class): Class_|null if ($constructClassMethod instanceof ClassMethod) { foreach ($constructClassMethod->getParams() as $param) { $this->visibilityManipulator->removeReadonly($param); + + if ($param->attrGroups !== []) { + $this->attributeGroupNewLiner->newLine($file, $param); + } } } foreach ($class->getProperties() as $property) { $this->visibilityManipulator->removeReadonly($property); + + if ($property->attrGroups !== []) { + $this->attributeGroupNewLiner->newLine($file, $property); + } + } + + if ($class->attrGroups !== []) { + $this->attributeGroupNewLiner->newLine($file, $class); } return $class; @@ -210,8 +225,8 @@ private function shouldSkipClass(Class_ $class): bool } return $class->extends instanceof FullyQualified && ! $this->reflectionProvider->hasClass( - $class->extends->toString() - ); + $class->extends->toString() + ); } /** diff --git a/rules/Php82/Rector/Class_/ReadOnlyClassRector.php b/rules/Php82/Rector/Class_/ReadOnlyClassRector.php index 8aad77813c9..41b58be53a7 100644 --- a/rules/Php82/Rector/Class_/ReadOnlyClassRector.php +++ b/rules/Php82/Rector/Class_/ReadOnlyClassRector.php @@ -68,7 +68,7 @@ public function refactor(Node $node): ?Node return null; } - return $this->readonlyClassManipulator->process($node); + return $this->readonlyClassManipulator->process($node, $this->file); } public function provideMinPhpVersion(): int