Passed
Push — feature/symfony6-upgrade ( 048052...a5554f )
by Paul
05:58
created

CustomLogoutListener::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Surfnet\StepupSelfService\SelfServiceBundle\Security\Authentication\EventSubscriber;
4
5
use Symfony\Component\HttpFoundation\RedirectResponse;
6
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
7
use Symfony\Component\Security\Http\Event\LogoutEvent;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10
readonly class CustomLogoutListener implements EventSubscriberInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class CustomLogoutListener
Loading history...
11
{
12
    public static function getSubscribedEvents(): array
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getSubscribedEvents()
Loading history...
13
    {
14
        return [
15
            LogoutEvent::class => 'onLogout',
16
        ];
17
    }
18
19
    public function __construct(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
20
        private TokenStorageInterface $tokenStorage,
21
        private array $logoutRedirectUrl,
22
    ) {
23
    }
24
    public function onLogout(): RedirectResponse
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function onLogout()
Loading history...
25
    {
26
        $token    = $this->tokenStorage->getToken();
27
        $identity = $token->getUser();
28
29
        return new RedirectResponse($this->logoutRedirectUrl[$identity->preferredLocale]);
0 ignored issues
show
Bug introduced by
Accessing preferredLocale on the interface Symfony\Component\Security\Core\User\UserInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
30
    }
31
32
}
33