Passed
Push — master ( 370563...eb17c3 )
by Angel Fernando Quiroz
10:49 queued 14s
created

SwitchUserSubscriber   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 4 1
A onSecuritySwitchUser() 0 9 3
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\EventSubscriber;
8
9
use Chamilo\CoreBundle\Entity\User;
10
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11
use Symfony\Component\Security\Http\Event\SwitchUserEvent;
12
13
class SwitchUserSubscriber implements EventSubscriberInterface
14
{
15
    public function onSecuritySwitchUser(SwitchUserEvent $event): void
16
    {
17
        $request = $event->getRequest();
18
19
        if ($request->hasSession() && ($session = $request->getSession())) {
20
            /** @var User $user */
21
            $user = $event->getTargetUser();
22
23
            $session->set('_locale_user', $user->getLocale());
24
        }
25
    }
26
27
    public static function getSubscribedEvents(): array
28
    {
29
        return [
30
            'security.switch_user' => 'onSecuritySwitchUser',
31
        ];
32
    }
33
}
34