Skip to content

Commit 477bea3

Browse files
authored
Support $classString::staticMethod() (#45)
1 parent a718a55 commit 477bea3

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/Collector/MethodCallCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ private function getMethodName(CallLike $call): ?string
200200
*/
201201
private function getReflectionsWithMethod(Type $type, string $methodName): iterable
202202
{
203-
$classReflections = $type->getObjectClassReflections();
203+
$classReflections = $type->getObjectTypeOrClassStringObjectType()->getObjectClassReflections();
204204

205205
foreach ($classReflections as $classReflection) {
206206
if ($classReflection->hasMethod($methodName)) {

tests/Rule/DeadMethodRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public static function provideFiles(): iterable
9090
yield 'dead-in-parent-1' => [__DIR__ . '/data/DeadMethodRule/dead-in-parent-1.php'];
9191
yield 'indirect-interface' => [__DIR__ . '/data/DeadMethodRule/indirect-interface.php'];
9292
yield 'attribute' => [__DIR__ . '/data/DeadMethodRule/attribute.php'];
93+
yield 'call-on-class-string' => [__DIR__ . '/data/DeadMethodRule/class-string.php'];
9394
yield 'array-map-1' => [__DIR__ . '/data/DeadMethodRule/array-map-1.php'];
9495
yield 'provider-default' => [__DIR__ . '/data/DeadMethodRule/providers/default.php'];
9596
yield 'provider-symfony' => [__DIR__ . '/data/DeadMethodRule/providers/symfony.php', 80_000];
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace ClassStringCall;
4+
5+
class ClassWithMethod {
6+
7+
public static function someMethod(): void {}
8+
}
9+
10+
/**
11+
* @param class-string<ClassWithMethod> $class
12+
*/
13+
function test(string $class): void {
14+
$class::someMethod();
15+
}

0 commit comments

Comments
 (0)