3
3
declare (strict_types=1 );
4
4
namespace Rector \Php81 \NodeManipulator ;
5
5
6
- use PhpParser \Node \Param ;
7
- use PhpParser \Node \Stmt \Class_ ;
8
- use PhpParser \Node \Stmt \Property ;
6
+ use PhpParser \Node ;
7
+ use PhpParser \Node \AttributeGroup ;
9
8
use Rector \ValueObject \Application \File ;
9
+ use RectorPrefix202508 \Webmozart \Assert \Assert ;
10
10
final class AttributeGroupNewLiner
11
11
{
12
- /**
13
- * @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param|\PhpParser\Node\Stmt\Class_ $node
14
- */
15
- public function newLine (File $ file , $ node ) : void
12
+ public function newLine (File $ file , Node $ node ) : void
16
13
{
14
+ $ attrGroups = $ node ->attrGroups ?? [];
15
+ if ($ attrGroups === []) {
16
+ return ;
17
+ }
18
+ Assert::allIsAOf ($ attrGroups , AttributeGroup::class);
19
+ Assert::isArray ($ attrGroups );
17
20
$ oldTokens = $ file ->getOldTokens ();
18
21
$ startTokenPos = $ node ->getStartTokenPos ();
19
22
if (!isset ($ oldTokens [$ startTokenPos ])) {
@@ -23,11 +26,11 @@ public function newLine(File $file, $node) : void
23
26
return ;
24
27
}
25
28
$ iteration = 1 ;
26
- $ lastKey = \array_key_last ($ node -> attrGroups );
29
+ $ lastKey = \array_key_last ($ attrGroups );
27
30
if ($ lastKey === null ) {
28
31
return ;
29
32
}
30
- $ lastAttributeTokenPos = $ node -> attrGroups [$ lastKey ]->getEndTokenPos ();
33
+ $ lastAttributeTokenPos = $ attrGroups [$ lastKey ]->getEndTokenPos ();
31
34
while (isset ($ oldTokens [$ startTokenPos + $ iteration ])) {
32
35
if ($ startTokenPos + $ iteration === $ lastAttributeTokenPos ) {
33
36
if ($ oldTokens [$ startTokenPos + $ iteration ]->text !== '] ' ) {
0 commit comments