ModuleSubscriber   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 51.43%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 13
c 2
b 0
f 2
lcom 1
cbo 4
dl 0
loc 84
ccs 18
cts 35
cp 0.5143
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getSubscribedEvents() 0 8 1
A preUpdate() 0 17 4
A prePersist() 0 12 3
A postRemove() 0 10 4
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: device
5
 * Date: 24.02.16
6
 * Time: 11:21
7
 */
8
9
namespace AppBundle\EventListener;
10
11
12
use AppBundle\Entity\Module;
13
use AppBundle\Services\ImageManagerServices;
14
use Doctrine\Common\EventSubscriber;
15
use Doctrine\ORM\Event\LifecycleEventArgs;
16
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
17
18
class ModuleSubscriber implements EventSubscriber
19
{
20
    /**
21
     * @var ImageManagerServices
22
     */
23
    protected $service;
24
25
    protected $cache;
26
27
28
    /**
29
     * @param ImageManagerServices $container
0 ignored issues
show
Bug introduced by
There is no parameter named $container. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
30
     */
31 27
    public function __construct(ImageManagerServices $service, CacheManager $cacheManager)
32
    {
33 27
        $this->service = $service;
34 27
        $this->cache = $cacheManager;
35
36 27
    }
37
38
    /**
39
     * @return array
40
     */
41 27
    public function getSubscribedEvents()
42
    {
43
        return array(
44 27
            'prePersist',
45 27
            'preUpdate',
46
            'postRemove'
47 27
        );
48
    }
49
50
    /**
51
     * @param LifecycleEventArgs $args
52
     */
53
    public function preUpdate(LifecycleEventArgs $args)
54
    {
55
        $module = $args->getEntity();
56
57
58
        if ($module instanceof Module) {
59
            if (null === $module->getModuleImage()) {
60
                return;
61
            }
62
            if (file_exists($module->getPathImage())) {
63
                unlink($module->getPathImage());
64
                $this->cache->remove($module->getPathImage());
65
            }
66
67
            $this->service->upload($module);
68
        }
69
    }
70
71
    /**
72
     * @param LifecycleEventArgs $args
73
     */
74 27
    public function prePersist(LifecycleEventArgs $args)
75
    {
76 27
        $module = $args->getEntity();
77
78 27
        if ($module instanceof Module) {
79 27
            if (null !== $module->getModuleImage()) {
80
                $this->service->upload($module);
81
            }
82
83
84 27
        }
85 27
    }
86
87
    /**
88
     * @param LifecycleEventArgs $args
89
     */
90 4
    public function postRemove(LifecycleEventArgs $args)
91
    {
92 4
        $module = $args->getEntity();
93
94 4
        if ($module instanceof Module && $module->getPathImage() !== null && file_exists($module->getPathImage())) {
95
            unlink($module->getPathImage());
96
            $this->cache->remove($module->getPathImage());
97
        }
98
99 4
    }
100
101
}