Skip to content

Commit

Permalink
RuleLevelHelper - consider trait as an unknown class
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 16, 2020
1 parent 67fc8f3 commit e089754
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Rules/RuleLevelHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
]);
}

Expand Down
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Methods/data/call-static-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,9 @@ public function doFoo(): void
TraitWithStaticMethod::doFoo();
}

public function doBar(TraitWithStaticMethod $a): void
{
$a::doFoo();
}

}

0 comments on commit e089754

Please sign in to comment.