SwitchUserListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A onSwitchUser() 0 5 1
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCacheBundle\EventListener;
13
14
use FOS\HttpCacheBundle\UserContextInvalidator;
15
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
use Symfony\Component\Security\Http\Event\SwitchUserEvent;
17
use Symfony\Component\Security\Http\SecurityEvents;
18
19
class SwitchUserListener implements EventSubscriberInterface
20
{
21
    private $invalidator;
22
23 3
    public function __construct(UserContextInvalidator $invalidator)
24
    {
25 3
        $this->invalidator = $invalidator;
26 3
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 2
    public static function getSubscribedEvents(): array
32
    {
33
        return [
34 2
            SecurityEvents::SWITCH_USER => 'onSwitchUser',
35
        ];
36
    }
37
38 2
    public function onSwitchUser(SwitchUserEvent $event)
39
    {
40 2
        $request = $event->getRequest();
41 2
        $this->invalidator->invalidateContext($request->getSession()->getId());
42 2
    }
43
}
44