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

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