Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Rector\Tests\DowngradePhp80\Rector\MethodCall\DowngradeNamedArgumentRector\Fixture;

final class RemoveFromUnknownType
{
function someMethod($container, $abstract, $parameters ) {
return $container->resolve($abstract, $parameters, raiseEvents: \true);
}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\MethodCall\DowngradeNamedArgumentRector\Fixture;

final class RemoveFromUnknownType
{
function someMethod($container, $abstract, $parameters ) {
return $container->resolve($abstract, $parameters, \true);
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpParser\Node\Expr\StaticCall;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\MixedType;
use Rector\DowngradePhp80\NodeAnalyzer\UnnamedArgumentResolver;
use Rector\NodeAnalyzer\ArgsAnalyzer;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -83,7 +84,7 @@ private function execute($a = null, $b = null)
public function refactor(Node $node): ?Node
{
$args = $node->getArgs();
if ($this->shouldSkip($args)) {
if (! $this->argsAnalyzer->hasNamedArg($args)) {
return null;
}

Expand All @@ -102,19 +103,26 @@ private function removeNamedArguments(MethodCall | StaticCall | New_ | FuncCall
}

if (! $functionLikeReflection instanceof MethodReflection && ! $functionLikeReflection instanceof FunctionReflection) {
// remove leftovers in case of unknown type, to avoid crashing on unknown syntax
if ($node instanceof MethodCall) {
$callerType = $this->getType($node->var);

if ($callerType instanceof MixedType) {
foreach ($node->getArgs() as $arg) {
if ($arg->name instanceof Node) {
$arg->name = null;
}
}

return $node;
}
}

return null;
}

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

return $node;
}

/**
* @param mixed[]|Arg[] $args
*/
private function shouldSkip(array $args): bool
{
return ! $this->argsAnalyzer->hasNamedArg($args);
}
}