From 917a527b6045122c55e45b754c8d45fc948aa91f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 6 Dec 2024 16:48:55 +0700 Subject: [PATCH] [scoped] Fix scoped prefixed UrlGeneratorInterface on RedirectToRouteRector (#692) * Fix scoped prefixed UrlGeneratorInterface on RedirectToRouteRector * clean up --- .../Rector/MethodCall/RedirectToRouteRector.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/rules/Symfony26/Rector/MethodCall/RedirectToRouteRector.php b/rules/Symfony26/Rector/MethodCall/RedirectToRouteRector.php index 5b7c6c90..488b05ac 100644 --- a/rules/Symfony26/Rector/MethodCall/RedirectToRouteRector.php +++ b/rules/Symfony26/Rector/MethodCall/RedirectToRouteRector.php @@ -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; @@ -20,8 +19,7 @@ final class RedirectToRouteRector extends AbstractRector { public function __construct( - private readonly ControllerAnalyzer $controllerAnalyzer, - private readonly ValueResolver $valueResolver + private readonly ControllerAnalyzer $controllerAnalyzer ) { } @@ -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'); } /**