Skip to content

Commit 3882cb5

Browse files
authored
fix: allow more nodes to be passed to AttributeGroupNewLiner (#7145)
1 parent 85e5e11 commit 3882cb5

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

rules/Php81/NodeManipulator/AttributeGroupNewLiner.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@
44

55
namespace Rector\Php81\NodeManipulator;
66

7-
use PhpParser\Node\Param;
8-
use PhpParser\Node\Stmt\Class_;
9-
use PhpParser\Node\Stmt\Property;
7+
use PhpParser\Node;
8+
use PhpParser\Node\AttributeGroup;
109
use Rector\ValueObject\Application\File;
10+
use Webmozart\Assert\Assert;
1111

1212
final class AttributeGroupNewLiner
1313
{
14-
public function newLine(File $file, Property|Param|Class_ $node): void
14+
public function newLine(File $file, Node $node): void
1515
{
16+
$attrGroups = $node->attrGroups ?? [];
17+
18+
if ($attrGroups === []) {
19+
return;
20+
}
21+
22+
Assert::allIsAOf($attrGroups, AttributeGroup::class);
23+
Assert::isArray($attrGroups);
24+
1625
$oldTokens = $file->getOldTokens();
1726
$startTokenPos = $node->getStartTokenPos();
1827

@@ -25,13 +34,13 @@ public function newLine(File $file, Property|Param|Class_ $node): void
2534
}
2635

2736
$iteration = 1;
28-
$lastKey = array_key_last($node->attrGroups);
37+
$lastKey = array_key_last($attrGroups);
2938

3039
if ($lastKey === null) {
3140
return;
3241
}
3342

34-
$lastAttributeTokenPos = $node->attrGroups[$lastKey]->getEndTokenPos();
43+
$lastAttributeTokenPos = $attrGroups[$lastKey]->getEndTokenPos();
3544

3645
while (isset($oldTokens[$startTokenPos + $iteration])) {
3746
if ($startTokenPos + $iteration === $lastAttributeTokenPos) {

0 commit comments

Comments
 (0)