Passed
Push — master ( e769ca...f1e182 )
by Stone
04:38
created

UserDeleteAccountSubscriber::deleteAccount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\EventSubscriber\User;
4
5
use App\Event\User\UserDeleteAccountEvent;
6
use App\Event\User\UserEvent;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
use Symfony\Component\HttpFoundation\Session\SessionInterface;
9
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
10
11
12
class UserDeleteAccountSubscriber extends UserSubscriber implements EventSubscriberInterface
13
{
14
15
    /**
16
     * @var SessionInterface
17
     */
18
    private $session;
19
    /**
20
     * @var TokenStorageInterface
21
     */
22
    private $tokenStorage;
23
24
    public function __construct(SessionInterface $session, TokenStorageInterface $tokenStorage)
25
    {
26
        $this->session = $session;
27
        $this->tokenStorage = $tokenStorage;
28
    }
29
30
    public function deleteAccount(UserEvent $event)
31
    {
32
        $this->deleteFromDatabase($event);
33
    }
34
35
    public function removeSession()
36
    {
37
        $this->tokenStorage->setToken(null);
38
        $this->session->invalidate();
39
    }
40
41
42
    /**
43
     * @return array The event names to listen to
44
     */
45
    public static function getSubscribedEvents()
46
    {
47
        return [
48
            UserDeleteAccountEvent::NAME => [
49
                ['deleteAccount', 50],
50
                ['removeSession', 40],
51
            ],
52
        ];
53
    }
54
}