Skip to content

Commit 58dce6e

Browse files
committed
[Php83] Skip ReadOnlyAnonymousClassRector on anonymous class with attributes
1 parent 74b7109 commit 58dce6e

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php83\Rector\Class_\ReadOnlyAnonymousClassRector\Fixture;
4+
5+
$attributed = new #[Tries(5)] class(4)
6+
{
7+
public function __construct(
8+
private readonly int $attempts,
9+
) {}
10+
11+
public function attempts(): int
12+
{
13+
return $this->attempts;
14+
}
15+
};

‎rules/Php83/Rector/Class_/ReadOnlyAnonymousClassRector.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public function refactor(Node $node): ?Node
6868
return null;
6969
}
7070

71+
// attribute between "new" and "class" cannot be format-preserving printed with an added readonly modifier
72+
if ($node->attrGroups !== []) {
73+
return null;
74+
}
75+
7176
return $this->readonlyClassManipulator->process($node);
7277
}
7378

0 commit comments

Comments
 (0)