Skip to content

Commit b4a6084

Browse files
xPawstaabm
andauthored
Add support for StaticCall (#766)
Co-authored-by: Markus Staab <maggus.staab@googlemail.com>
1 parent a5cee18 commit b4a6084

13 files changed

+201
-255
lines changed

.phpstan-dba-mysqli.cache

Lines changed: 1 addition & 241 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.phpstan-dba-pdo-mysql.cache

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Rules/QueryPlanAnalyzerRule.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use PhpParser\Node\Expr\CallLike;
99
use PhpParser\Node\Expr\MethodCall;
1010
use PhpParser\Node\Expr\New_;
11+
use PhpParser\Node\Expr\StaticCall;
12+
use PhpParser\Node\Identifier;
13+
use PhpParser\Node\Name;
1114
use PhpParser\Node\Name\FullyQualified;
1215
use PHPStan\Analyser\Scope;
1316
use PHPStan\Reflection\ReflectionProvider;
@@ -30,7 +33,7 @@ final class QueryPlanAnalyzerRule implements Rule
3033
/**
3134
* @var list<string>
3235
*/
33-
private array $classMethods;
36+
public array $classMethods;
3437

3538
private ReflectionProvider $reflectionProvider;
3639

@@ -56,6 +59,15 @@ public function processNode(Node $callLike, Scope $scope): array
5659
}
5760

5861
$methodReflection = $scope->getMethodReflection($scope->getType($callLike->var), $callLike->name->toString());
62+
} elseif ($callLike instanceof StaticCall) {
63+
if (! $callLike->name instanceof Identifier) {
64+
return [];
65+
}
66+
if (! $callLike->class instanceof Name) {
67+
return [];
68+
}
69+
$classType = $scope->resolveTypeByName($callLike->class);
70+
$methodReflection = $scope->getMethodReflection($classType, $callLike->name->toString());
5971
} elseif ($callLike instanceof New_) {
6072
if (! $callLike->class instanceof FullyQualified) {
6173
return [];
@@ -105,7 +117,7 @@ public function processNode(Node $callLike, Scope $scope): array
105117
}
106118

107119
/**
108-
* @param MethodCall|New_ $callLike
120+
* @param MethodCall|StaticCall|New_ $callLike
109121
*
110122
* @return list<IdentifierRuleError>
111123
*/

src/Rules/SyntaxErrorInPreparedStatementMethodRule.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use PhpParser\Node\Expr\CallLike;
99
use PhpParser\Node\Expr\MethodCall;
1010
use PhpParser\Node\Expr\New_;
11+
use PhpParser\Node\Expr\StaticCall;
12+
use PhpParser\Node\Identifier;
13+
use PhpParser\Node\Name;
1114
use PhpParser\Node\Name\FullyQualified;
1215
use PHPStan\Analyser\Scope;
1316
use PHPStan\Reflection\ReflectionProvider;
@@ -57,6 +60,15 @@ public function processNode(Node $callLike, Scope $scope): array
5760
}
5861

5962
$methodReflection = $scope->getMethodReflection($scope->getType($callLike->var), $callLike->name->toString());
63+
} elseif ($callLike instanceof StaticCall) {
64+
if (! $callLike->name instanceof Identifier) {
65+
return [];
66+
}
67+
if (! $callLike->class instanceof Name) {
68+
return [];
69+
}
70+
$classType = $scope->resolveTypeByName($callLike->class);
71+
$methodReflection = $scope->getMethodReflection($classType, $callLike->name->toString());
6072
} elseif ($callLike instanceof New_) {
6173
if (! $callLike->class instanceof FullyQualified) {
6274
return [];
@@ -96,7 +108,7 @@ public function processNode(Node $callLike, Scope $scope): array
96108
}
97109

98110
/**
99-
* @param MethodCall|New_ $callLike
111+
* @param MethodCall|StaticCall|New_ $callLike
100112
*
101113
* @return list<IdentifierRuleError>
102114
*/

0 commit comments

Comments
 (0)