Skip to content

Commit

Permalink
[scoped] Fix scoped prefixed UrlGeneratorInterface on RedirectToRoute…
Browse files Browse the repository at this point in the history
…Rector (#692)

* Fix scoped prefixed UrlGeneratorInterface on RedirectToRouteRector

* clean up
  • Loading branch information
samsonasik authored Dec 6, 2024
1 parent 7e1cc10 commit 917a527
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions rules/Symfony26/Rector/MethodCall/RedirectToRouteRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\MethodCall;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Rector\AbstractRector;
use Rector\Symfony\TypeAnalyzer\ControllerAnalyzer;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -20,8 +19,7 @@
final class RedirectToRouteRector extends AbstractRector
{
public function __construct(
private readonly ControllerAnalyzer $controllerAnalyzer,
private readonly ValueResolver $valueResolver
private readonly ControllerAnalyzer $controllerAnalyzer
) {
}

Expand Down Expand Up @@ -99,7 +97,15 @@ private function isDefaultReferenceType(MethodCall $methodCall): bool
return false;
}

return $this->valueResolver->isValue($refTypeArg->value, UrlGeneratorInterface::ABSOLUTE_PATH);
if (! $refTypeArg->value instanceof ClassConstFetch) {
return false;
}

if (! $this->isName($refTypeArg->value->class, 'Symfony\Component\Routing\Generator\UrlGeneratorInterface')) {
return false;
}

return $this->isName($refTypeArg->value->name, 'ABSOLUTE_PATH');
}

/**
Expand Down

0 comments on commit 917a527

Please sign in to comment.