Skip to content

Commit e089754

Browse files
committed
RuleLevelHelper - consider trait as an unknown class
1 parent 67fc8f3 commit e089754

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/Rules/RuleLevelHelper.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ public function findTypeToCheck(
172172
$directClassNames = TypeUtils::getDirectClassNames($type);
173173
foreach ($directClassNames as $referencedClass) {
174174
if ($this->reflectionProvider->hasClass($referencedClass)) {
175-
continue;
175+
$classReflection = $this->reflectionProvider->getClass($referencedClass);
176+
if (!$classReflection->isTrait()) {
177+
continue;
178+
}
176179
}
177180

178181
$errors[] = RuleErrorBuilder::message(sprintf($unknownClassErrorPattern, $referencedClass))->line($var->getLine())->build();

tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ public function testCallStaticMethods(): void
220220
'Call to static method doFoo() on trait CallStaticMethods\TraitWithStaticMethod.',
221221
323,
222222
],
223+
[
224+
'Call to static method doFoo() on an unknown class CallStaticMethods\TraitWithStaticMethod.',
225+
328,
226+
],
223227
]);
224228
}
225229

tests/PHPStan/Rules/Methods/data/call-static-methods.php

+5
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,9 @@ public function doFoo(): void
323323
TraitWithStaticMethod::doFoo();
324324
}
325325

326+
public function doBar(TraitWithStaticMethod $a): void
327+
{
328+
$a::doFoo();
329+
}
330+
326331
}

0 commit comments

Comments
 (0)