1212use PhpParser \Node \Expr \StaticCall ;
1313use PHPStan \Reflection \FunctionReflection ;
1414use PHPStan \Reflection \MethodReflection ;
15+ use PHPStan \Type \MixedType ;
1516use Rector \DowngradePhp80 \NodeAnalyzer \UnnamedArgumentResolver ;
1617use Rector \NodeAnalyzer \ArgsAnalyzer ;
1718use Rector \Rector \AbstractRector ;
@@ -83,7 +84,7 @@ private function execute($a = null, $b = null)
8384 public function refactor (Node $ node ): ?Node
8485 {
8586 $ args = $ node ->getArgs ();
86- if ($ this ->shouldSkip ($ args )) {
87+ if (! $ this ->argsAnalyzer -> hasNamedArg ($ args )) {
8788 return null ;
8889 }
8990
@@ -102,19 +103,26 @@ private function removeNamedArguments(MethodCall | StaticCall | New_ | FuncCall
102103 }
103104
104105 if (! $ functionLikeReflection instanceof MethodReflection && ! $ functionLikeReflection instanceof FunctionReflection) {
106+ // remove leftovers in case of unknown type, to avoid crashing on unknown syntax
107+ if ($ node instanceof MethodCall) {
108+ $ callerType = $ this ->getType ($ node ->var );
109+
110+ if ($ callerType instanceof MixedType) {
111+ foreach ($ node ->getArgs () as $ arg ) {
112+ if ($ arg ->name instanceof Node) {
113+ $ arg ->name = null ;
114+ }
115+ }
116+
117+ return $ node ;
118+ }
119+ }
120+
105121 return null ;
106122 }
107123
108124 $ node ->args = $ this ->unnamedArgumentResolver ->resolveFromReflection ($ functionLikeReflection , $ args );
109125
110126 return $ node ;
111127 }
112-
113- /**
114- * @param mixed[]|Arg[] $args
115- */
116- private function shouldSkip (array $ args ): bool
117- {
118- return ! $ this ->argsAnalyzer ->hasNamedArg ($ args );
119- }
120128}
0 commit comments