ModuleSubscriber::postRemove()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 5.2596

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 10
ccs 4
cts 7
cp 0.5714
rs 9.2
cc 4
eloc 5
nc 2
nop 1
crap 5.2596
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
}