Passed
Pull Request — master (#6127)
by Angel Fernando Quiroz
07:52
created

H5pImportEventSubscriber   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 26
rs 10
c 1
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 4 1
A __construct() 0 3 1
A onCreateCourse() 0 10 4
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
use Chamilo\CoreBundle\Event\CourseCreatedEvent;
8
use Chamilo\CoreBundle\Event\AbstractEvent;
9
use Chamilo\CoreBundle\Event\Events;
10
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11
12
class H5pImportEventSubscriber implements EventSubscriberInterface
13
{
14
    private H5pImportPlugin $plugin;
15
16
    public function __construct()
17
    {
18
        $this->plugin = H5pImportPlugin::create();
19
    }
20
21
    public static function getSubscribedEvents(): array
22
    {
23
        return [
24
            Events::COURSE_CREATED => 'onCreateCourse',
25
        ];
26
    }
27
28
    public function onCreateCourse(CourseCreatedEvent $event): void
29
    {
30
        if (!$this->plugin->isEnabled(true)) {
31
            return;
32
        }
33
34
        $course = $event->getCourse();
35
36
        if (AbstractEvent::TYPE_POST === $event->getType() && $course) {
37
            $this->plugin->addCourseTool($course->getId());
38
        }
39
    }
40
}
41