Skip to content

Commit 5cda01b

Browse files
phpstan-botclaude
andcommitted
Add tests for MethodCallReturnTypeHelper fallback on static calls
Tests the generic fallback logic in MethodCallReturnTypeHelper for static method calls on union types where only some classes are handled by dynamic return type extensions. Uses BackedEnum::from() as the extension-handled case and a plain class as the unhandled fallback case. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3847d6a commit 5cda01b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php // lint >= 8.1
2+
3+
namespace MethodCallReturnTypeFallback;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
enum Suit: string {
8+
case Hearts = 'hearts';
9+
case Diamonds = 'diamonds';
10+
}
11+
12+
class MyClass {
13+
/** @return self */
14+
public static function from(string $value): self {
15+
return new self();
16+
}
17+
}
18+
19+
/** @param class-string<Suit>|class-string<MyClass> $class */
20+
function testStaticCallOnUnionWithConstant(string $class): void {
21+
assertType('MethodCallReturnTypeFallback\MyClass|MethodCallReturnTypeFallback\Suit::Hearts', $class::from('hearts'));
22+
}
23+
24+
/** @param class-string<Suit>|class-string<MyClass> $class */
25+
function testStaticCallOnUnionWithVariable(string $class, string $value): void {
26+
assertType('MethodCallReturnTypeFallback\MyClass|MethodCallReturnTypeFallback\Suit', $class::from($value));
27+
}

0 commit comments

Comments
 (0)