Skip to content

Commit 07378ca

Browse files
committed
remove unclear type named args
1 parent 05bf931 commit 07378ca

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

rules/DowngradePhp80/Rector/MethodCall/DowngradeNamedArgumentRector.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PhpParser\Node\Expr\StaticCall;
1313
use PHPStan\Reflection\FunctionReflection;
1414
use PHPStan\Reflection\MethodReflection;
15+
use PHPStan\Type\MixedType;
1516
use Rector\DowngradePhp80\NodeAnalyzer\UnnamedArgumentResolver;
1617
use Rector\NodeAnalyzer\ArgsAnalyzer;
1718
use 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

Comments
 (0)