33namespace MabeEnumPHPStan ;
44
55use MabeEnum \Enum ;
6- use PhpParser \Node \Expr ;
76use PhpParser \Node \Expr \MethodCall ;
87use PhpParser \Node \Expr \StaticCall ;
8+ use PhpParser \Node \Name ;
99use PHPStan \Analyser \Scope ;
1010use PHPStan \Reflection \MethodReflection ;
1111use PHPStan \Reflection \ParametersAcceptorSelector ;
@@ -56,7 +56,7 @@ public function __construct()
5656 };
5757 }
5858
59- // static methods cann be called like object methods
59+ // static methods can be called like object methods
6060 $ this ->objectMethods = array_merge ($ this ->objectMethods , $ this ->staticMethods );
6161 }
6262
@@ -82,23 +82,28 @@ public function getTypeFromStaticMethodCall(
8282 StaticCall $ staticCall ,
8383 Scope $ scope
8484 ): Type {
85- if ($ staticCall ->class instanceof Expr) {
85+ $ callClass = $ staticCall ->class ;
86+
87+ // The call class is not a name
88+ // E.g. an expression on $enumClass::getValues()
89+ if (!$ callClass instanceof Name) {
8690 return ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ())->getReturnType ();
8791 }
88- $ callClass = $ staticCall ->class ->toString ();
92+
93+ $ callClassName = $ callClass ->toString ();
8994
9095 // Can't detect possible types on static::*()
9196 // as it depends on defined enumerators of unknown inherited classes
92- if ($ callClass === 'static ' ) {
97+ if ($ callClassName === 'static ' ) {
9398 return ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ())->getReturnType ();
9499 }
95100
96- if ($ callClass === 'self ' ) {
97- $ callClass = $ scope ->getClassReflection ()->getName ();
101+ if ($ callClassName === 'self ' ) {
102+ $ callClassName = $ scope ->getClassReflection ()->getName ();
98103 }
99104
100105 $ methodLower = strtolower ($ methodReflection ->getName ());
101- return $ this ->objectMethods [$ methodLower ]($ callClass );
106+ return $ this ->staticMethods [$ methodLower ]($ callClassName );
102107 }
103108
104109 public function getTypeFromMethodCall (
0 commit comments