Skip to content

Commit e4c78b2

Browse files
committed
[DeadCode] Skip with assign to call with target has #[NoDiscard] attribute
1 parent dddda67 commit e4c78b2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
use PhpParser\Node\Expr;
99
use PhpParser\Node\Expr\Assign;
1010
use PhpParser\Node\Expr\AssignRef;
11-
use PhpParser\Node\Expr\CallLike;
1211
use PhpParser\Node\Expr\Cast;
1312
use PhpParser\Node\Expr\Closure;
1413
use PhpParser\Node\Expr\FuncCall;
1514
use PhpParser\Node\Expr\Include_;
15+
use PhpParser\Node\Expr\MethodCall;
16+
use PhpParser\Node\Expr\New_;
17+
use PhpParser\Node\Expr\NullsafeMethodCall;
18+
use PhpParser\Node\Expr\StaticCall;
1619
use PhpParser\Node\Expr\Variable;
1720
use PhpParser\Node\Stmt;
1821
use PhpParser\Node\Stmt\Class_;
@@ -270,7 +273,11 @@ function (Node $subNode) use (&$refVariableNames) {
270273
continue;
271274
}
272275

273-
if ($assign->expr instanceof CallLike) {
276+
if ($assign->expr instanceof FuncCall
277+
|| $assign->expr instanceof StaticCall
278+
|| $assign->expr instanceof MethodCall
279+
|| $assign->expr instanceof New_
280+
|| $assign->expr instanceof NullsafeMethodCall) {
274281
$targetCall = $this->astResolver->resolveClassMethodOrFunctionFromCall($assign->expr);
275282
if (($targetCall instanceof ClassMethod || $targetCall instanceof Function_)
276283
&& $this->phpAttributeAnalyzer->hasPhpAttribute($targetCall, 'NoDiscard')) {

0 commit comments

Comments
 (0)