Skip to content

Commit ad986e0

Browse files
committed
Leverage late static binding for instantiation methods in PHPStan extension
1 parent 478612e commit ad986e0

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/FlaggedEnum.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use BenSampo\Enum\Exceptions\InvalidEnumMemberException;
66

7+
/**
8+
* @method static static None()
9+
*/
710
abstract class FlaggedEnum extends Enum
811
{
912
/**

src/PHPStan/EnumMethodReflection.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,15 @@
88
use PHPStan\Reflection\MethodReflection;
99
use PHPStan\TrinaryLogic;
1010
use PHPStan\Type\Generic\TemplateTypeMap;
11-
use PHPStan\Type\ObjectType;
11+
use PHPStan\Type\StaticType;
1212
use PHPStan\Type\Type;
1313

1414
class EnumMethodReflection implements MethodReflection
1515
{
16-
/**
17-
* @var \PHPStan\Reflection\ClassReflection
18-
*/
19-
private $classReflection;
20-
21-
/**
22-
* @var string
23-
*/
24-
private $name;
25-
26-
public function __construct(ClassReflection $classReflection, string $name)
27-
{
28-
$this->classReflection = $classReflection;
29-
$this->name = $name;
16+
public function __construct(
17+
private ClassReflection $classReflection,
18+
private string $name
19+
) {
3020
}
3121

3222
public function getDeclaringClass(): ClassReflection
@@ -68,7 +58,7 @@ public function getVariants(): array
6858
null,
6959
[],
7060
false,
71-
new ObjectType($this->classReflection->getName())
61+
new StaticType($this->classReflection)
7262
),
7363
];
7464
}

0 commit comments

Comments
 (0)