@@ -2029,36 +2029,47 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
2029
2029
);
2030
2030
}
2031
2031
2032
- if ($ node instanceof MethodCall && $ node ->name instanceof Node \Identifier) {
2033
- if ($ this ->nativeTypesPromoted ) {
2032
+ if ($ node instanceof MethodCall) {
2033
+ if ($ node ->name instanceof Node \Identifier) {
2034
+ if ($ this ->nativeTypesPromoted ) {
2035
+ $ typeCallback = function () use ($ node ): Type {
2036
+ $ methodReflection = $ this ->getMethodReflection (
2037
+ $ this ->getNativeType ($ node ->var ),
2038
+ $ node ->name ->name ,
2039
+ );
2040
+ if ($ methodReflection === null ) {
2041
+ return new ErrorType ();
2042
+ }
2043
+
2044
+ return ParametersAcceptorSelector::combineAcceptors ($ methodReflection ->getVariants ())->getNativeReturnType ();
2045
+ };
2046
+
2047
+ return $ this ->getNullsafeShortCircuitingType ($ node ->var , $ typeCallback ());
2048
+ }
2049
+
2034
2050
$ typeCallback = function () use ($ node ): Type {
2035
- $ methodReflection = $ this ->getMethodReflection (
2036
- $ this ->getNativeType ($ node ->var ),
2051
+ $ returnType = $ this ->methodCallReturnType (
2052
+ $ this ->getType ($ node ->var ),
2037
2053
$ node ->name ->name ,
2054
+ $ node ,
2038
2055
);
2039
- if ($ methodReflection === null ) {
2056
+ if ($ returnType === null ) {
2040
2057
return new ErrorType ();
2041
2058
}
2042
-
2043
- return ParametersAcceptorSelector::combineAcceptors ($ methodReflection ->getVariants ())->getNativeReturnType ();
2059
+ return $ returnType ;
2044
2060
};
2045
2061
2046
2062
return $ this ->getNullsafeShortCircuitingType ($ node ->var , $ typeCallback ());
2047
2063
}
2048
2064
2049
- $ typeCallback = function () use ($ node ): Type {
2050
- $ returnType = $ this ->methodCallReturnType (
2051
- $ this ->getType ($ node ->var ),
2052
- $ node ->name ->name ,
2053
- $ node ,
2065
+ $ nameType = $ this ->getType ($ node ->name );
2066
+ if (count ($ nameType ->getConstantStrings ()) > 0 ) {
2067
+ return TypeCombinator::union (
2068
+ ...array_map (fn ($ constantString ) => $ this
2069
+ ->filterByTruthyValue (new BinaryOp \Identical ($ node ->name , new String_ ($ constantString ->getValue ())))
2070
+ ->getType (new MethodCall ($ node ->var , new Identifier ($ constantString ->getValue ()), $ node ->args )), $ nameType ->getConstantStrings ()),
2054
2071
);
2055
- if ($ returnType === null ) {
2056
- return new ErrorType ();
2057
- }
2058
- return $ returnType ;
2059
- };
2060
-
2061
- return $ this ->getNullsafeShortCircuitingType ($ node ->var , $ typeCallback ());
2072
+ }
2062
2073
}
2063
2074
2064
2075
if ($ node instanceof Expr \NullsafeMethodCall) {
0 commit comments