@@ -23,38 +23,36 @@ class EnumDynamicReturnTypeExtension implements DynamicStaticMethodReturnTypeExt
2323 *
2424 * @var array<string, callable>
2525 */
26- private $ objectMethods = [];
26+ private array $ objectMethods = [];
2727
2828 /**
2929 * Map supported static method to a callable function detecting return type
3030 *
3131 * @var array<string, callable>
3232 */
33- private $ staticMethods = [];
33+ private array $ staticMethods = [];
3434
3535 /**
3636 * Buffer of all types of enumeration values
3737 * @phpstan-var array<class-string<Enum>, Type[]>
3838 */
39- private $ enumValueTypesBuffer = [];
39+ private array $ enumValueTypesBuffer = [];
4040
4141 /**
4242 * Buffer of all types of enumeration ordinals
4343 * @phpstan-var array<class-string<Enum>, Type[]>
4444 */
45- private $ enumOrdinalTypesBuffer = [];
45+ private array $ enumOrdinalTypesBuffer = [];
4646
4747 public function __construct ()
4848 {
4949 $ this ->objectMethods ['getvalue ' ] = function (string $ class ) {
5050 return $ this ->detectGetValueReturnType ($ class );
5151 };
5252
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+ };
5856
5957 // static methods can be called like object methods
6058 $ this ->objectMethods = array_merge ($ this ->objectMethods , $ this ->staticMethods );
@@ -87,15 +85,23 @@ public function getTypeFromStaticMethodCall(
8785 // The call class is not a name
8886 // E.g. an expression on $enumClass::getValues()
8987 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 ();
9193 }
9294
9395 $ callClassName = $ callClass ->toString ();
9496
9597 // Can't detect possible types on static::*()
9698 // as it depends on defined enumerators of unknown inherited classes
9799 if ($ callClassName === 'static ' ) {
98- return ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ())->getReturnType ();
100+ return ParametersAcceptorSelector::selectFromArgs (
101+ $ scope ,
102+ $ staticCall ->getArgs (),
103+ $ methodReflection ->getVariants ()
104+ )->getReturnType ();
99105 }
100106
101107 if ($ callClassName === 'self ' ) {
0 commit comments