@@ -40,24 +40,34 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
40
40
return in_array (strtolower ($ methodReflection ->getName ()), $ supportedMethods , true );
41
41
}
42
42
43
- public function getTypeFromMethodCall (MethodReflection $ methodReflection , MethodCall $ methodCall , Scope $ scope ): Type
44
- {
45
- $ enumType = $ scope ->getType ($ methodCall ->var );
46
- $ methodName = $ methodReflection ->getName ();
47
- $ methodClasses = $ enumType ->getReferencedClasses ();
48
- if (count ($ methodClasses ) !== 1 ) {
49
- return ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ())->getReturnType ();
50
- }
43
+ public function getTypeFromMethodCall (
44
+ MethodReflection $ methodReflection ,
45
+ MethodCall $ methodCall ,
46
+ Scope $ scope
47
+ ): Type {
48
+ $ type = $ scope ->getType ($ methodCall ->var );
49
+ $ typeClasses = $ type ->getReferencedClasses ();
51
50
52
- $ enumeration = $ methodClasses [0 ];
51
+ $ valuesTypeAll = null ;
52
+ foreach ($ typeClasses as $ typeClass ) {
53
+ if (!is_subclass_of ($ typeClass , Enum::class, true )) {
54
+ return ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ())->getReturnType ();
55
+ }
56
+
57
+ $ valuesType = $ this ->getEnumValuesType ($ typeClass , $ scope );
58
+ $ valuesTypeAll = $ valuesTypeAll
59
+ ? TypeCombinator::union ($ valuesTypeAll , $ valuesType )
60
+ : $ valuesType ;
61
+ }
53
62
63
+ $ methodName = $ methodReflection ->getName ();
54
64
switch (strtolower ($ methodName )) {
55
65
case 'getvalue ' :
56
- return $ this -> getEnumValuesType ( $ enumeration , $ scope ) ;
66
+ return $ valuesTypeAll ;
57
67
case 'getvalues ' :
58
68
return new ArrayType (
59
69
new IntegerType (),
60
- $ this -> getEnumValuesType ( $ enumeration , $ scope )
70
+ $ valuesTypeAll
61
71
);
62
72
default :
63
73
throw new ShouldNotHappenException ("Method {$ methodName } is not supported " );
0 commit comments