Test Failed
Push — develop ( c35c51...0616cb )
by Stone
04:36 queued 10s
created

DeleteImageController::deleteTrickImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Controller\Image;
4
5
use App\Entity\Image;
6
use App\Event\Image\ImageDeleteEvent;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
8
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
10
use Symfony\Component\Routing\Annotation\Route;
11
12
/**
13
 * Class DeleteImageController
14
 * @package App\Controller\Image
15
 * @IsGranted("ROLE_USER")
16
 */
17
class DeleteImageController extends AbstractController
18
{
19
20
    /**
21
     * @var EventDispatcherInterface
22
     */
23
    private $dispatcher;
24
25
    public function __construct(EventDispatcherInterface $dispatcher)
26
    {
27
        $this->dispatcher = $dispatcher;
28
    }
29
30
    /**
31
     * @Route("/image/delete/{id}", name="image.deleteFromTrick", methods={"POST"})
32
     * @param Image $image
33
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
34
     */
35
    public function deleteTrickImage(Image $image)
36
    {
37
        $trick = $image->getTrick();
38
        $event = new ImageDeleteEvent($image, $image->getTrick());
0 ignored issues
show
Bug introduced by
It seems like $image->getTrick() can also be of type null; however, parameter $trick of App\Event\Image\ImageDeleteEvent::__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

38
        $event = new ImageDeleteEvent($image, /** @scrutinizer ignore-type */ $image->getTrick());
Loading history...
39
        $this->dispatcher->dispatch(ImageDeleteEvent::NAME, $event);
40
41
        return $this->redirectToRoute('trick.edit', [
42
            'id' => $trick->getId(),
43
        ]);
44
    }
45
}