From 6bd2ffef8c1a325550eaa38f1f14bc8b85d2b98a Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 26 Sep 2025 16:56:49 +0200 Subject: [PATCH] etract enum --- ...utSuccessHandlerToLogoutEventSubscriberRector.php | 12 ++++-------- src/Enum/SymfonyClass.php | 5 +++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/rules/Symfony51/Rector/Class_/LogoutSuccessHandlerToLogoutEventSubscriberRector.php b/rules/Symfony51/Rector/Class_/LogoutSuccessHandlerToLogoutEventSubscriberRector.php index 22519b2c1..0368bfe40 100644 --- a/rules/Symfony51/Rector/Class_/LogoutSuccessHandlerToLogoutEventSubscriberRector.php +++ b/rules/Symfony51/Rector/Class_/LogoutSuccessHandlerToLogoutEventSubscriberRector.php @@ -10,6 +10,7 @@ use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Type\ObjectType; use Rector\Rector\AbstractRector; +use Rector\Symfony\Enum\SymfonyClass; use Rector\Symfony\NodeAnalyzer\ClassAnalyzer; use Rector\Symfony\NodeFactory\GetSubscribedEventsClassMethodFactory; use Rector\Symfony\NodeFactory\OnSuccessLogoutClassMethodFactory; @@ -31,9 +32,7 @@ public function __construct( private readonly GetSubscribedEventsClassMethodFactory $getSubscribedEventsClassMethodFactory, private readonly ClassAnalyzer $classAnalyzer, ) { - $this->successHandlerObjectType = new ObjectType( - 'Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface' - ); + $this->successHandlerObjectType = new ObjectType(SymfonyClass::LOGOUT_SUCCESS_HANDLER); } public function getRuleDefinition(): RuleDefinition @@ -120,16 +119,13 @@ public function refactor(Node $node): ?Node return null; } - if (! $this->classAnalyzer->hasImplements( - $node, - 'Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface' - )) { + if (! $this->classAnalyzer->hasImplements($node, SymfonyClass::LOGOUT_SUCCESS_HANDLER)) { return null; } $this->refactorImplements($node); - $node->implements[] = new FullyQualified('Symfony\Component\EventDispatcher\EventSubscriberInterface'); + $node->implements[] = new FullyQualified(SymfonyClass::EVENT_SUBSCRIBER_INTERFACE); // 2. refactor logout() class method to onLogout() $onLogoutSuccessClassMethod = null; diff --git a/src/Enum/SymfonyClass.php b/src/Enum/SymfonyClass.php index daa14aa08..f28124e67 100644 --- a/src/Enum/SymfonyClass.php +++ b/src/Enum/SymfonyClass.php @@ -145,4 +145,9 @@ final class SymfonyClass * @var string */ public const SYMFONY_STYLE = 'Symfony\Component\Console\Style\SymfonyStyle'; + + /** + * @var string + */ + public const LOGOUT_SUCCESS_HANDLER = 'Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface'; }