Passed
Push — develop ( fd2651...23d7f3 )
by Stone
04:24
created

UserDeleteAccountSubscriber::removeSession()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\HttpFoundation\Session\SessionInterface;
11
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
12
13
14
class UserDeleteAccountSubscriber extends UserSubscriber implements EventSubscriberInterface
15
{
16
17
    /**
18
 * @var Session
19
 */
20
    private $session;
21
    /**
22
     * @var TokenStorageInterface
23
     */
24
    private $tokenStorage;
25
26
    public function __construct(SessionInterface $session, TokenStorageInterface $tokenStorage)
27
    {
28
        $this->session = $session;
0 ignored issues
show
Documentation Bug introduced by
$session is of type Symfony\Component\HttpFo...ession\SessionInterface, but the property $session was declared to be of type Symfony\Component\HttpFoundation\Session\Session. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
29
        $this->tokenStorage = $tokenStorage;
30
    }
31
32
    public function deleteAccount(UserEvent $event)
33
    {
34
        $this->deleteFromDatabase($event);
35
    }
36
37
    public function removeSession()
38
    {
39
        $this->tokenStorage->setToken(null);
40
        $this->session->invalidate();
41
    }
42
43
44
    /**
45
     * @return array The event names to listen to
46
     */
47
    public static function getSubscribedEvents()
48
    {
49
        return [
50
            UserDeleteAccountEvent::NAME => [
51
                ['deleteAccount', 50],
52
                ['removeSession', 40],
53
            ],
54
        ];
55
    }
56
}