Skip to content

Commit a6b5203

Browse files
authored
[Php81] Handle crash on normal array with variadic inside class on ArrayToFirstClassCallableRector (#7966)
* [Php81] Handle crash on normal array with variadic inside class on ArrayToFirstClassCallableRector * Fix * clean up
1 parent 4273c16 commit a6b5203

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php81\Rector\Array_\ArrayToFirstClassCallableRector\Fixture;
4+
5+
final class SkipNormalArrayWithVariadic
6+
{
7+
private function foo(mixed ...$args): void {}
8+
9+
public function test(): void
10+
{
11+
$this->foo('first', ['key' => 'value'], c: 'test');
12+
}
13+
}

src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Error;
88
use PhpParser\Node;
9-
use PhpParser\Node\Arg;
109
use PhpParser\Node\ArrayItem;
1110
use PhpParser\Node\Expr;
1211
use PhpParser\Node\Expr\Array_;
@@ -277,11 +276,6 @@ public function processNodes(
277276
return;
278277
}
279278

280-
if ($node instanceof Arg) {
281-
$node->value->setAttribute(AttributeKey::SCOPE, $mutatingScope);
282-
return;
283-
}
284-
285279
if ($node instanceof Foreach_) {
286280
// decorate value as well
287281
$node->valueVar->setAttribute(AttributeKey::SCOPE, $mutatingScope);
@@ -492,6 +486,14 @@ private function processCallLike(CallLike $callLike, MutatingScope $mutatingScop
492486
} elseif ($callLike instanceof New_ && ! $callLike->class instanceof Class_) {
493487
$callLike->class->setAttribute(AttributeKey::SCOPE, $mutatingScope);
494488
}
489+
490+
if ($callLike->isFirstClassCallable()) {
491+
return;
492+
}
493+
494+
foreach ($callLike->getArgs() as $arg) {
495+
$arg->value->setAttribute(AttributeKey::SCOPE, $mutatingScope);
496+
}
495497
}
496498

497499
private function processAssign(Assign|AssignOp|AssignRef $assign, MutatingScope $mutatingScope): void

0 commit comments

Comments
 (0)