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

VideoDeletedSubscriber   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 9
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteVideoFromDatabase() 0 11 1
A getSubscribedEvents() 0 4 1
1
<?php
2
3
namespace App\EventSubscriber\Video;
4
5
use App\Event\Video\VideoDeleteEvent;
6
use App\Event\Video\VideoEvent;
7
use App\FlashMessage\FlashMessageCategory;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10
class VideoDeletedSubscriber extends VideoSubscriber implements EventSubscriberInterface
11
{
12
    /**
13
     * Send Image to the database and set a flash message
14
     * @param VideoEvent $event
15
     */
16
    public function deleteVideoFromDatabase(VideoEvent $event)
17
    {
18
        $video = $event->getEntity();
19
20
        $trick = $event->getTrick();
21
22
        $trick->removeVideo($video);
23
        $this->em->persist($trick);
24
        $this->em->flush();
25
26
        $this->addFlash(FlashMessageCategory::SUCCESS, 'Video '. $video->getTitle() .' deleted');
27
    }
28
29
    /**
30
     * @return array The event names to listen to
31
     */
32
    public static function getSubscribedEvents()
33
    {
34
        return [
35
            VideoDeleteEvent::NAME => 'deleteVideoFromDatabase',
36
        ];
37
    }
38
}