Test Failed
Branch develop (47adb0)
by Stone
04:36
created

DeleteVideoController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\Request;
12
use Symfony\Component\Routing\Annotation\Route;
13
14
/**
15
 * Class DeleteImageController
16
 * @package App\Controller\Image
17
 * @IsGranted("ROLE_USER")
18
 */
19
class DeleteVideoController extends AbstractController
20
{
21
22
    /**
23
     * @var EventDispatcherInterface
24
     */
25
    private $dispatcher;
26
27
    public function __construct(EventDispatcherInterface $dispatcher)
28
    {
29
        $this->dispatcher = $dispatcher;
30
    }
31
32
    /**
33
     * @Route("/video/delete/{id}", name="video.deleteFromTrick", methods={"POST"})
34
     * @param Video $video
35
     * @param Request $request
36
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
37
     */
38
    public function deleteTrickImage(video $video, Request $request)
39
    {
40
        $submittedToken = $request->request->get('_token');
41
        if (!$this->isCsrfTokenValid('delete-video' . $video->getId(), $submittedToken)) {
42
            throw new RedirectException($this->generateUrl('home'), 'Bad CSRF Token');
43
        }
44
45
        $trick = $video->getTrick();
46
        $event = new VideoDeleteEvent($video, $video->getTrick());
0 ignored issues
show
Bug introduced by
It seems like $video->getTrick() can also be of type null; however, parameter $trick of App\Event\Video\VideoDeleteEvent::__construct() does only seem to accept App\Entity\Trick, 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

46
        $event = new VideoDeleteEvent($video, /** @scrutinizer ignore-type */ $video->getTrick());
Loading history...
47
        $this->dispatcher->dispatch(VideoDeleteEvent::NAME, $event);
48
49
        return $this->redirectToRoute('trick.edit', [
50
            'id' => $trick->getId(),
51
        ]);
52
    }
53
}