diff --git a/src/Rules/Methods/StaticMethodCallCheck.php b/src/Rules/Methods/StaticMethodCallCheck.php index aaabe3d1e79..6feb0b1c4a8 100644 --- a/src/Rules/Methods/StaticMethodCallCheck.php +++ b/src/Rules/Methods/StaticMethodCallCheck.php @@ -24,8 +24,10 @@ use PHPStan\Rules\RuleLevelHelper; use PHPStan\ShouldNotHappenException; use PHPStan\TrinaryLogic; +use PHPStan\Type\ClassStringType; use PHPStan\Type\ErrorType; use PHPStan\Type\Generic\GenericClassStringType; +use PHPStan\Type\ObjectWithoutClassType; use PHPStan\Type\StaticType; use PHPStan\Type\StringType; use PHPStan\Type\Type; @@ -200,11 +202,14 @@ public function check( if (!$classType->isObject()->yes()) { return [[], null]; } + } elseif ($classType instanceof ClassStringType) { // @phpstan-ignore phpstanApi.instanceofType + $typeForDescribe = $classType; + $classType = new ObjectWithoutClassType(); } elseif ($classType->isString()->yes()) { return [[], null]; } - $typeForDescribe = $classType; + $typeForDescribe ??= $classType; if ($classType instanceof StaticType) { $typeForDescribe = $classType->getStaticObjectType(); } diff --git a/tests/PHPStan/Analyser/nsrt/bug-9844.php b/tests/PHPStan/Analyser/nsrt/bug-9844.php new file mode 100644 index 00000000000..03d1f09139a --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-9844.php @@ -0,0 +1,17 @@ +checkThisOnly = false; + $this->checkExplicitMixed = false; + $this->checkImplicitMixed = false; + $this->analyse([__DIR__ . '/data/bug-9844.php'], [ + [ + 'Call to an undefined static method class-string::foo().', + 13, + ], + [ + 'Call to an undefined static method object::foo().', + 21, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Methods/data/bug-9844.php b/tests/PHPStan/Rules/Methods/data/bug-9844.php new file mode 100644 index 00000000000..cb8dba22489 --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-9844.php @@ -0,0 +1,23 @@ +