Skip to content

Commit 57b0ae0

Browse files
committed
Fix PossiblyPureFuncCallCollector
1 parent 1d61059 commit 57b0ae0

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/Rules/DeadCode/PossiblyPureFuncCallCollector.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace PHPStan\Rules\DeadCode;
44

55
use PhpParser\Node;
6-
use PhpParser\Node\Expr\FuncCall;
6+
use PhpParser\Node\Stmt\Expression;
77
use PHPStan\Analyser\Scope;
88
use PHPStan\Collectors\Collector;
99
use PHPStan\Reflection\ReflectionProvider;
1010

1111
/**
12-
* @implements Collector<FuncCall, array{string, int}>
12+
* @implements Collector<Node\Stmt\Expression, array{string, int}>
1313
*/
1414
class PossiblyPureFuncCallCollector implements Collector
1515
{
@@ -20,20 +20,23 @@ public function __construct(private ReflectionProvider $reflectionProvider)
2020

2121
public function getNodeType(): string
2222
{
23-
return FuncCall::class;
23+
return Expression::class;
2424
}
2525

2626
public function processNode(Node $node, Scope $scope)
2727
{
28-
if (!$node->name instanceof Node\Name) {
28+
if (!$node->expr instanceof Node\Expr\FuncCall) {
29+
return null;
30+
}
31+
if (!$node->expr->name instanceof Node\Name) {
2932
return null;
3033
}
3134

32-
if (!$this->reflectionProvider->hasFunction($node->name, $scope)) {
35+
if (!$this->reflectionProvider->hasFunction($node->expr->name, $scope)) {
3336
return null;
3437
}
3538

36-
$functionReflection = $this->reflectionProvider->getFunction($node->name, $scope);
39+
$functionReflection = $this->reflectionProvider->getFunction($node->expr->name, $scope);
3740
if (!$functionReflection->isPure()->maybe()) {
3841
return null;
3942
}

tests/PHPStan/Rules/DeadCode/data/call-to-function-without-impure-points.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ function (): void {
3131
funcWithRef();
3232
impureFunc();
3333
callingImpureFunc();
34+
35+
$a = myFunc();
3436
};

0 commit comments

Comments
 (0)