diff --git a/src/Rules/Methods/CallPrivateMethodThroughStaticRule.php b/src/Rules/Methods/CallPrivateMethodThroughStaticRule.php index 8fd13a19e54..5cc4f28227a 100644 --- a/src/Rules/Methods/CallPrivateMethodThroughStaticRule.php +++ b/src/Rules/Methods/CallPrivateMethodThroughStaticRule.php @@ -36,7 +36,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - $classType = $scope->resolveTypeByName($className); + $classType = $scope->getType(new Node\Expr\ClassConstFetch(new Name('static'), 'class'))->getClassStringObjectType(); if (!$classType->hasMethod($methodName)->yes()) { return []; } diff --git a/tests/PHPStan/Rules/Methods/CallPrivateMethodThroughStaticRuleTest.php b/tests/PHPStan/Rules/Methods/CallPrivateMethodThroughStaticRuleTest.php index 25cd02b49bf..bc3997f873a 100644 --- a/tests/PHPStan/Rules/Methods/CallPrivateMethodThroughStaticRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallPrivateMethodThroughStaticRuleTest.php @@ -26,4 +26,14 @@ public function testRule(): void ]); } + public function testInstanceof(): void + { + $this->analyse([__DIR__ . '/data/call-private-method-static-instanceof.php'], [ + [ + 'Unsafe call to private method CallPrivateMethodStaticInstanceof\FooBase::fooPrivate() through static::.', + 27, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Methods/data/call-private-method-static-instanceof.php b/tests/PHPStan/Rules/Methods/data/call-private-method-static-instanceof.php new file mode 100644 index 00000000000..ae1490ed448 --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/call-private-method-static-instanceof.php @@ -0,0 +1,29 @@ +