@@ -23,38 +23,36 @@ class EnumDynamicReturnTypeExtension implements DynamicStaticMethodReturnTypeExt
23
23
*
24
24
* @var array<string, callable>
25
25
*/
26
- private $ objectMethods = [];
26
+ private array $ objectMethods = [];
27
27
28
28
/**
29
29
* Map supported static method to a callable function detecting return type
30
30
*
31
31
* @var array<string, callable>
32
32
*/
33
- private $ staticMethods = [];
33
+ private array $ staticMethods = [];
34
34
35
35
/**
36
36
* Buffer of all types of enumeration values
37
37
* @phpstan-var array<class-string<Enum>, Type[]>
38
38
*/
39
- private $ enumValueTypesBuffer = [];
39
+ private array $ enumValueTypesBuffer = [];
40
40
41
41
/**
42
42
* Buffer of all types of enumeration ordinals
43
43
* @phpstan-var array<class-string<Enum>, Type[]>
44
44
*/
45
- private $ enumOrdinalTypesBuffer = [];
45
+ private array $ enumOrdinalTypesBuffer = [];
46
46
47
47
public function __construct ()
48
48
{
49
49
$ this ->objectMethods ['getvalue ' ] = function (string $ class ) {
50
50
return $ this ->detectGetValueReturnType ($ class );
51
51
};
52
52
53
- if (method_exists (Enum::class, 'getvalues ' )) {
54
- $ this ->staticMethods ['getvalues ' ] = function (string $ class ) {
55
- return $ this ->detectGetValuesReturnType ($ class );
56
- };
57
- }
53
+ $ this ->staticMethods ['getvalues ' ] = function (string $ class ) {
54
+ return $ this ->detectGetValuesReturnType ($ class );
55
+ };
58
56
59
57
// static methods can be called like object methods
60
58
$ this ->objectMethods = array_merge ($ this ->objectMethods , $ this ->staticMethods );
@@ -87,15 +85,23 @@ public function getTypeFromStaticMethodCall(
87
85
// The call class is not a name
88
86
// E.g. an expression on $enumClass::getValues()
89
87
if (!$ callClass instanceof Name) {
90
- return ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ())->getReturnType ();
88
+ return ParametersAcceptorSelector::selectFromArgs (
89
+ $ scope ,
90
+ $ staticCall ->getArgs (),
91
+ $ methodReflection ->getVariants ()
92
+ )->getReturnType ();
91
93
}
92
94
93
95
$ callClassName = $ callClass ->toString ();
94
96
95
97
// Can't detect possible types on static::*()
96
98
// as it depends on defined enumerators of unknown inherited classes
97
99
if ($ callClassName === 'static ' ) {
98
- return ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ())->getReturnType ();
100
+ return ParametersAcceptorSelector::selectFromArgs (
101
+ $ scope ,
102
+ $ staticCall ->getArgs (),
103
+ $ methodReflection ->getVariants ()
104
+ )->getReturnType ();
99
105
}
100
106
101
107
if ($ callClassName === 'self ' ) {
0 commit comments