Passed
Pull Request — main (#308)
by Paul
14:27 queued 07:29
created

CustomLogoutListener   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 7
c 4
b 0
f 0
dl 0
loc 20
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A onLogout() 0 12 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\Bundle\SecurityBundle\Security;
8
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
use Symfony\Component\Security\Http\Event\LogoutEvent;
11
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
12
13
readonly class CustomLogoutListener
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class CustomLogoutListener
Loading history...
14
{
15
    public function __construct(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
16
        private Security $security,
17
        private array $logoutRedirectUrl,
18
    ) {
19
    }
20
21
    #[AsEventListener(event: LogoutEvent::class)]
22
    public function onLogout(LogoutEvent $event): void
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function onLogout()
Loading history...
23
    {
24
        $identity = $this->security->getUser()->getIdentity();
0 ignored issues
show
Bug introduced by
The method getIdentity() does not exist on Symfony\Component\Security\Core\User\UserInterface. It seems like you code against a sub-type of Symfony\Component\Security\Core\User\UserInterface such as Surfnet\StepupSelfServic...n\AuthenticatedIdentity. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        $identity = $this->security->getUser()->/** @scrutinizer ignore-call */ getIdentity();
Loading history...
25
26
        $logoutRedirectUrl = $this->logoutRedirectUrl[$identity->preferredLocale];
27
28
        $event->getRequest()->getSession()->invalidate();
29
30
        $response = new RedirectResponse($logoutRedirectUrl);
31
32
        $event->setResponse($response);
33
    }
34
}
35