From e089754fca006d0465bdd0ba0b40482f550254fb Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 16 Mar 2020 13:05:38 +0100 Subject: [PATCH] RuleLevelHelper - consider trait as an unknown class --- src/Rules/RuleLevelHelper.php | 5 ++++- tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php | 4 ++++ tests/PHPStan/Rules/Methods/data/call-static-methods.php | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Rules/RuleLevelHelper.php b/src/Rules/RuleLevelHelper.php index 384379d10e..ec1d6562c8 100644 --- a/src/Rules/RuleLevelHelper.php +++ b/src/Rules/RuleLevelHelper.php @@ -172,7 +172,10 @@ public function findTypeToCheck( $directClassNames = TypeUtils::getDirectClassNames($type); foreach ($directClassNames as $referencedClass) { if ($this->reflectionProvider->hasClass($referencedClass)) { - continue; + $classReflection = $this->reflectionProvider->getClass($referencedClass); + if (!$classReflection->isTrait()) { + continue; + } } $errors[] = RuleErrorBuilder::message(sprintf($unknownClassErrorPattern, $referencedClass))->line($var->getLine())->build(); diff --git a/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php index bb2e1c1f85..ad79048399 100644 --- a/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php @@ -220,6 +220,10 @@ public function testCallStaticMethods(): void 'Call to static method doFoo() on trait CallStaticMethods\TraitWithStaticMethod.', 323, ], + [ + 'Call to static method doFoo() on an unknown class CallStaticMethods\TraitWithStaticMethod.', + 328, + ], ]); } diff --git a/tests/PHPStan/Rules/Methods/data/call-static-methods.php b/tests/PHPStan/Rules/Methods/data/call-static-methods.php index 7d210b951c..96e370b430 100644 --- a/tests/PHPStan/Rules/Methods/data/call-static-methods.php +++ b/tests/PHPStan/Rules/Methods/data/call-static-methods.php @@ -323,4 +323,9 @@ public function doFoo(): void TraitWithStaticMethod::doFoo(); } + public function doBar(TraitWithStaticMethod $a): void + { + $a::doFoo(); + } + }