Skip to content

Commit 5078be3

Browse files
authored
etract enum (#850)
1 parent 3848c83 commit 5078be3

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

rules/Symfony51/Rector/Class_/LogoutSuccessHandlerToLogoutEventSubscriberRector.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpParser\Node\Stmt\ClassMethod;
1111
use PHPStan\Type\ObjectType;
1212
use Rector\Rector\AbstractRector;
13+
use Rector\Symfony\Enum\SymfonyClass;
1314
use Rector\Symfony\NodeAnalyzer\ClassAnalyzer;
1415
use Rector\Symfony\NodeFactory\GetSubscribedEventsClassMethodFactory;
1516
use Rector\Symfony\NodeFactory\OnSuccessLogoutClassMethodFactory;
@@ -31,9 +32,7 @@ public function __construct(
3132
private readonly GetSubscribedEventsClassMethodFactory $getSubscribedEventsClassMethodFactory,
3233
private readonly ClassAnalyzer $classAnalyzer,
3334
) {
34-
$this->successHandlerObjectType = new ObjectType(
35-
'Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface'
36-
);
35+
$this->successHandlerObjectType = new ObjectType(SymfonyClass::LOGOUT_SUCCESS_HANDLER);
3736
}
3837

3938
public function getRuleDefinition(): RuleDefinition
@@ -120,16 +119,13 @@ public function refactor(Node $node): ?Node
120119
return null;
121120
}
122121

123-
if (! $this->classAnalyzer->hasImplements(
124-
$node,
125-
'Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface'
126-
)) {
122+
if (! $this->classAnalyzer->hasImplements($node, SymfonyClass::LOGOUT_SUCCESS_HANDLER)) {
127123
return null;
128124
}
129125

130126
$this->refactorImplements($node);
131127

132-
$node->implements[] = new FullyQualified('Symfony\Component\EventDispatcher\EventSubscriberInterface');
128+
$node->implements[] = new FullyQualified(SymfonyClass::EVENT_SUBSCRIBER_INTERFACE);
133129

134130
// 2. refactor logout() class method to onLogout()
135131
$onLogoutSuccessClassMethod = null;

src/Enum/SymfonyClass.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,9 @@ final class SymfonyClass
145145
* @var string
146146
*/
147147
public const SYMFONY_STYLE = 'Symfony\Component\Console\Style\SymfonyStyle';
148+
149+
/**
150+
* @var string
151+
*/
152+
public const LOGOUT_SUCCESS_HANDLER = 'Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface';
148153
}

0 commit comments

Comments
 (0)