Skip to content

Commit 05e8819

Browse files
[CodeQuality] Handle crash on echo with first class callable on OptionalParametersAfterRequiredRector (#6553)
* [CodeQuality] Handle crash on echo with first class callable on OptionalParametersAfterRequiredRector * fix * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <[email protected]>
1 parent 22275db commit 05e8819

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector\Fixture;
6+
7+
final class SkipFirstClassCallableInEcho
8+
{
9+
public function getSubscribedEvents()
10+
{
11+
echo $this->textElement(...);
12+
}
13+
14+
public function textElement() { return 'test'; }
15+
}

src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
use PhpParser\Node\Stmt\ClassConst;
6363
use PhpParser\Node\Stmt\ClassLike;
6464
use PhpParser\Node\Stmt\ClassMethod;
65+
use PhpParser\Node\Stmt\Echo_;
6566
use PhpParser\Node\Stmt\Enum_;
6667
use PhpParser\Node\Stmt\EnumCase;
6768
use PhpParser\Node\Stmt\Expression;
@@ -367,6 +368,11 @@ public function processNodes(
367368
$this->processIssetOrUnset($node, $mutatingScope);
368369
return;
369370
}
371+
372+
if ($node instanceof Echo_) {
373+
$this->processEcho($node, $mutatingScope);
374+
return;
375+
}
370376
};
371377

372378
$this->nodeScopeResolverProcessNodes($stmts, $scope, $nodeCallback);
@@ -401,6 +407,13 @@ private function processIssetOrUnset(Isset_|Unset_ $node, MutatingScope $mutatin
401407
}
402408
}
403409

410+
private function processEcho(Echo_ $echo, MutatingScope $mutatingScope): void
411+
{
412+
foreach ($echo->exprs as $expr) {
413+
$expr->setAttribute(AttributeKey::SCOPE, $mutatingScope);
414+
}
415+
}
416+
404417
private function processMatch(Match_ $match, MutatingScope $mutatingScope): void
405418
{
406419
$match->cond->setAttribute(AttributeKey::SCOPE, $mutatingScope);

0 commit comments

Comments
 (0)