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

UserProfileDeleteController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Controller\Profile;
4
5
use App\Event\User\UserDeleteAccountEvent;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
7
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
8
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\Routing\Annotation\Route;
11
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
12
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
13
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
14
15
/**
16
 * Class UserProfileDeleteController
17
 * @package App\Controller\Profile
18
 * @IsGranted("ROLE_USER")
19
 */
20
class UserProfileDeleteController extends AbstractController
21
{
22
23
    /**
24
     * @var EventDispatcherInterface
25
     */
26
    private $dispatcher;
27
28
    public function __construct(EventDispatcherInterface $dispatcher)
29
    {
30
31
        $this->dispatcher = $dispatcher;
32
    }
33
34
    /**
35
     * @Route("/profile/delete", name="admin.delete_profile")
36
     */
37
    public function deleteProfile(Request $request, TokenStorageInterface $tokenStorage)
38
    {
39
        //TODO:; Csrf Protection
40
        $user = $this->getUser();
41
42
        $event = new UserDeleteAccountEvent($user);
0 ignored issues
show
Bug introduced by
It seems like $user can also be of type null; however, parameter $user of App\Event\User\UserDelet...untEvent::__construct() does only seem to accept App\Entity\User, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
        $event = new UserDeleteAccountEvent(/** @scrutinizer ignore-type */ $user);
Loading history...
43
        $this->dispatcher->dispatch(UserDeleteAccountEvent::NAME, $event);
44
45
        $tokenStorage->setToken(null);
46
        $request->getSession()->invalidate();
47
48
        return $this->redirectToRoute('home');
49
50
    }
51
}