Test Failed
Push — develop ( 4c8119...e64b8e )
by Stone
04:27
created

UserDeleteAccountSubscriber   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 7
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 5 1
A deleteAccount() 0 6 1
1
<?php
2
3
namespace App\EventSubscriber\User;
4
5
use App\Event\User\UserDeleteAccountEvent;
6
use App\Event\User\UserEvent;
7
use App\FlashMessage\FlashMessageCategory;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
use Symfony\Component\HttpFoundation\Session\Session;
10
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
11
12
13
class UserDeleteAccountSubscriber extends UserSubscriber implements EventSubscriberInterface
14
{
15
16
//    /**
17
//     * @var Session
18
//     */
19
//    private $session;
20
//    /**
21
//     * @var TokenStorageInterface
22
//     */
23
//    private $tokenStorage;
24
//
25
//    public function __construct(Session $session, TokenStorageInterface $tokenStorage)
26
//    {
27
//        $this->session = $session;
28
//        $this->tokenStorage = $tokenStorage;
29
//    }
30
31
    public function deleteAccount(UserEvent $event)
32
    {
33
        /** @var \App\Entity\User $user */
34
        $user = $event->getEntity();
35
        $this->deleteFromDatabase($event);
36
        $this->addFlash(FlashMessageCategory::INFO, 'account '.$user->getUsername().' deleted');
37
38
    }
39
40
//    public function removeSession(UserEvent $event){
41
//        $this->get('security.context')->setToken(null);
42
//        $this->get('request')->getSession()->invalidate();
43
//    }
44
45
46
    /**
47
     * @return array The event names to listen to
48
     */
49
    public static function getSubscribedEvents()
50
    {
51
        return [
52
            UserDeleteAccountEvent::NAME => [
53
                ['deleteAccount', 50],
54
            ],
55
        ];
56
    }
57
}