Passed
Pull Request — main (#308)
by Paul
13:45 queued 06:35
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
12
readonly class CustomLogoutListener
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class CustomLogoutListener
Loading history...
13
{
14
    public function __construct(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
15
        private Security $security,
16
        private array $logoutRedirectUrl,
17
    ) {
18
    }
19
20
    #[AsEventListener(event: LogoutEvent::class)]
21
    public function onLogout(LogoutEvent $event): void
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function onLogout()
Loading history...
22
    {
23
        $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

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