VideoAddedSubscriber   A
last analyzed

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