MediasListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 3 Features 0
Metric Value
wmc 4
c 4
b 3
f 0
lcom 1
cbo 2
dl 0
loc 31
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A preRemove() 0 10 2
A getSubscribedEvents() 0 6 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Rafidion Michael
5
 * Date: 12/12/2014
6
 * Time: 12:21
7
 */
8
9
namespace Mykees\MediaBundle\EventListener;
10
11
use Doctrine\ORM\Events;
12
use Doctrine\ORM\Event\LifecycleEventArgs;
13
use Mykees\MediaBundle\Interfaces\Mediable;
14
use Doctrine\Common\Persistence\ManagerRegistry;
15
use Mykees\MediaBundle\Manager\MediaManager;
16
17
class MediasListener
18
{
19
    public $managerRegistry;
20
    public $rootDir;
21
    public $resize_parameters;
22
23
    public function __construct(ManagerRegistry $managerRegistry, $rootDir, $resize_parameters)
24
    {
25
        $this->managerRegistry = $managerRegistry;
26
        $this->rootDir = $rootDir;
27
        $this->resize_parameters = $resize_parameters;
28
    }
29
30
    public function preRemove(LifecycleEventArgs $args)
31
    {
32
        $model = $args->getEntity();
33
34
        if($model instanceof Mediable)
35
        {
36
            $manager = new MediaManager($this->managerRegistry,$this->rootDir,$this->resize_parameters);
37
            $manager->removeAllMediasForModel($model);
38
        }
39
    }
40
41
    public function getSubscribedEvents()
42
    {
43
        return [
44
            Events::preRemove
45
        ];
46
    }
47
}
48