DeleteVideoController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

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