EntityListenerResolver::resolve()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
/**
3
 * @year    2016
4
 * @author  Lobanov Aleksandr <[email protected]>
5
 */
6
7
namespace Nnx\Doctrine\Resolver;
8
9
use Doctrine\ORM\Mapping\DefaultEntityListenerResolver;
10
use Zend\ServiceManager\ServiceLocatorInterface;
11
12
/**
13
 * Class EntityListenerResolver
14
 *
15
 * @package Nnx\Doctrine\Resolver
16
 */
17
class EntityListenerResolver extends DefaultEntityListenerResolver
18
{
19
20
    /**
21
     * @var ServiceLocatorInterface
22
     */
23
    private $container;
24
25
    /**
26
     * EntityListenerResolver constructor.
27
     *
28
     * @param ServiceLocatorInterface $container
29
     */
30
    public function __construct(ServiceLocatorInterface $container)
31
    {
32
        $this->container = $container;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function resolve($className)
39
    {
40
        if ($this->getContainer()->has($className)) {
41
            $object = $this->getContainer()->get($className);
42
            $this->register($object);
0 ignored issues
show
Bug introduced by
It seems like $object defined by $this->getContainer()->get($className) on line 41 can also be of type array; however, Doctrine\ORM\Mapping\Def...nerResolver::register() does only seem to accept object, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
43
        }
44
        return parent::resolve($className);
45
    }
46
47
    /**
48
     * @return ServiceLocatorInterface
49
     */
50
    protected function getContainer()
51
    {
52
        return $this->container;
53
    }
54
}
55