Skip to content

Commit 8a5d242

Browse files
committed
remove unclear type named args
1 parent 05bf931 commit 8a5d242

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

rules/DowngradePhp80/Rector/MethodCall/DowngradeNamedArgumentRector.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private function execute($a = null, $b = null)
8383
public function refactor(Node $node): ?Node
8484
{
8585
$args = $node->getArgs();
86-
if ($this->shouldSkip($args)) {
86+
if (! $this->argsAnalyzer->hasNamedArg($args)) {
8787
return null;
8888
}
8989

@@ -102,19 +102,26 @@ private function removeNamedArguments(MethodCall | StaticCall | New_ | FuncCall
102102
}
103103

104104
if (! $functionLikeReflection instanceof MethodReflection && ! $functionLikeReflection instanceof FunctionReflection) {
105+
// remove leftovers in case of unknown type, to avoid crashing on unknown syntax
106+
if ($node instanceof MethodCall) {
107+
$callerType = $this->getType($node->var);
108+
109+
if ($callerType instanceof \PHPStan\Type\MixedType) {
110+
foreach ($node->getArgs() as $arg) {
111+
if ($arg->name instanceof Node) {
112+
$arg->name = null;
113+
}
114+
}
115+
116+
return $node;
117+
}
118+
}
119+
105120
return null;
106121
}
107122

108123
$node->args = $this->unnamedArgumentResolver->resolveFromReflection($functionLikeReflection, $args);
109124

110125
return $node;
111126
}
112-
113-
/**
114-
* @param mixed[]|Arg[] $args
115-
*/
116-
private function shouldSkip(array $args): bool
117-
{
118-
return ! $this->argsAnalyzer->hasNamedArg($args);
119-
}
120127
}

0 commit comments

Comments
 (0)