Skip to content

Commit 8832cc5

Browse files
Rework
1 parent 5a008c6 commit 8832cc5

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/Type/ValueOfType.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@ public function isResolvable(): bool
5151
protected function getResult(): Type
5252
{
5353
if ($this->type->isEnum()->yes()) {
54+
$enumCases = $this->type->getEnumCases();
5455
if (
55-
$this->type instanceof TemplateType
56-
&& $this->type->getBound()->equals(new ObjectType('BackedEnum'))
56+
$enumCases === []
57+
&& $this->type instanceof TemplateType
58+
&& (new ObjectType('BackedEnum'))->isSuperTypeOf($this->type->getBound())->yes()
5759
) {
5860
return new UnionType([new IntegerType(), new StringType()]);
5961
}
6062

6163
$valueTypes = [];
62-
foreach ($this->type->getEnumCases() as $enumCase) {
64+
foreach ($enumCases as $enumCase) {
6365
$valueType = $enumCase->getBackingValueType();
6466
if ($valueType === null) {
6567
continue;

tests/PHPStan/Rules/Methods/data/bug-12219.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,31 @@ public function bar(string $class, mixed $value): void
2424
$this->foo($class, $value);
2525
}
2626
}
27+
28+
interface SuperBackedEnum extends \BackedEnum
29+
{
30+
public function customMethod(): void;
31+
}
32+
33+
class Bug2
34+
{
35+
/**
36+
* @template T of SuperBackedEnum
37+
* @param class-string<T> $class
38+
* @param value-of<T> $value
39+
*/
40+
public function foo(string $class, mixed $value): void
41+
{
42+
}
43+
44+
/**
45+
* @template Q of SuperBackedEnum
46+
* @param class-string<Q> $class
47+
* @param value-of<Q> $value
48+
*/
49+
public function bar(string $class, mixed $value): void
50+
{
51+
// Parameter #2 $value of static method Bug::foo() contains unresolvable type.
52+
$this->foo($class, $value);
53+
}
54+
}

0 commit comments

Comments
 (0)