Passed
Pull Request — main (#308)
by Paul
16:16 queued 09:55
created

CustomLogoutListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A onLogout() 0 6 1
A getSubscribedEvents() 0 4 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
declare(strict_types = 1);
4
5
namespace Surfnet\StepupSelfService\SelfServiceBundle\Security\Authentication\EventSubscriber;
6
7
use Symfony\Component\HttpFoundation\RedirectResponse;
8
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
9
use Symfony\Component\Security\Http\Event\LogoutEvent;
10
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11
12
readonly class CustomLogoutListener implements EventSubscriberInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class CustomLogoutListener
Loading history...
13
{
14
    public static function getSubscribedEvents(): array
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getSubscribedEvents()
Loading history...
15
    {
16
        return [
17
            LogoutEvent::class => 'onLogout',
18
        ];
19
    }
20
21
    public function __construct(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
22
        private TokenStorageInterface $tokenStorage,
23
        private array $logoutRedirectUrl,
24
    ) {
25
    }
26
    public function onLogout(): RedirectResponse
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function onLogout()
Loading history...
27
    {
28
        $token    = $this->tokenStorage->getToken();
29
        $identity = $token->getUser();
30
31
        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...
32
    }
33
}
34