DeleteTrickController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 9
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 0 12 2
A __construct() 0 3 1
1
<?php
2
3
namespace App\Controller\Trick\Admin;
4
5
use App\Entity\Trick;
6
use App\Event\Trick\TrickDeletedEvent;
7
use App\Exception\RedirectException;
8
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
10
use Symfony\Component\HttpFoundation\RedirectResponse;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\Routing\Annotation\Route;
13
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
14
15
/**
16
 * Class TrickEditController
17
 * @package App\Controller\Edit
18
 *
19
 * Require the user to be connected for everything here
20
 * @IsGranted("ROLE_USER")
21
 */
22
class DeleteTrickController extends AbstractController
23
{
24
    /**
25
     * @var EventDispatcherInterface
26
     */
27
    private $dispatcher;
28
29
    public function __construct(EventDispatcherInterface $dispatcher)
30
    {
31
        $this->dispatcher = $dispatcher;
32
    }
33
34
    /**
35
     * @Route("/trick/delete/{id}", name="trick.delete", methods={"POST"})
36
     * @param Trick $trick
37
     * @param Request $request
38
     * @return RedirectResponse
39
     */
40
    public function delete(Trick $trick, Request $request)
41
    {
42
43
        $submittedToken = $request->request->get('_token');
44
        if (!$this->isCsrfTokenValid('delete-trick' . $trick->getId(), $submittedToken)) {
45
            throw new RedirectException($this->generateUrl('home'), 'Bad CSRF Token');
46
        }
47
48
        $event = new TrickDeletedEvent($trick);
49
        $this->dispatcher->dispatch(TrickDeletedEvent::NAME, $event);
50
51
        return $this->redirectToRoute('home');
52
53
    }
54
55
56
}