Completed
Push — dev ( 896128...070006 )
by Андрей
02:25
created

OrmEntityLocator::getModuleOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/doctrine
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\Doctrine\EntityManager;
7
8
use Nnx\Doctrine\ObjectManager\ObjectManagerAutoDetectorInterface;
9
use Nnx\Doctrine\Options\ModuleOptions;
10
use Nnx\Doctrine\Options\ModuleOptionsInterface;
11
12
/**
13
 * Class OrmAbstractFactory
14
 *
15
 * @package Nnx\Doctrine\EntityManager
16
 */
17
class OrmEntityLocator implements OrmEntityLocatorInterface
18
{
19
    /**
20
     * @var array
21
     */
22
    protected $entityClassNameCache = [];
23
24
    /**
25
     * @var ObjectManagerAutoDetectorInterface
26
     */
27
    protected $objectManagerAutoDetector;
28
29
    /**
30
     * Настройки модуля
31
     *
32
     * @var ModuleOptions
33
     */
34
    protected $moduleOptions;
35
36
    /**
37
     * OrmEntityLocator constructor.
38
     *
39
     * @param ObjectManagerAutoDetectorInterface $objectManagerAutoDetector
40
     * @param ModuleOptionsInterface             $moduleOptions
41
     */
42
    public function __construct(ObjectManagerAutoDetectorInterface $objectManagerAutoDetector, ModuleOptionsInterface $moduleOptions)
43
    {
44
        $this->setObjectManagerAutoDetector($objectManagerAutoDetector);
45
        $this->setModuleOptions($moduleOptions);
46
    }
47
48
49
    /**
50
     * @inheritdoc
51
     *
52
     * @param string $id
53
     *
54
     * @return bool
55
     */
56
    public function get($id)
57
    {
58
    }
59
60
    /**
61
     * @inheritdoc
62
     *
63
     * @param string $id
64
     *
65
     * @return mixed
66
     */
67
    public function has($id)
68
    {
69
        $objectManagerAutoDetector = $this->getObjectManagerAutoDetector();
70
        if (!$objectManagerAutoDetector->hasObjectManagerNameByClassName($id)) {
71
            return false;
72
        }
73
        $objectManagerName = $objectManagerAutoDetector->getObjectManagerNameByClassName($id);
0 ignored issues
show
Unused Code introduced by
$objectManagerName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
74
75
76
77
        return ;
78
    }
79
80
81
82
83
84
85
    /**
86
     * @return ObjectManagerAutoDetectorInterface
87
     */
88
    public function getObjectManagerAutoDetector()
89
    {
90
        return $this->objectManagerAutoDetector;
91
    }
92
93
    /**
94
     * @param ObjectManagerAutoDetectorInterface $objectManagerAutoDetector
95
     *
96
     * @return $this
97
     */
98
    public function setObjectManagerAutoDetector($objectManagerAutoDetector)
99
    {
100
        $this->objectManagerAutoDetector = $objectManagerAutoDetector;
101
102
        return $this;
103
    }
104
105
    /**
106
     * Возвращает настройки модуля
107
     *
108
     * @return ModuleOptionsInterface
109
     */
110
    public function getModuleOptions()
111
    {
112
        return $this->moduleOptions;
113
    }
114
115
    /**
116
     * Устанавливает настройки модуля
117
     *
118
     * @param ModuleOptionsInterface $moduleOptions
119
     *
120
     * @return $this
121
     */
122
    public function setModuleOptions(ModuleOptionsInterface $moduleOptions)
123
    {
124
        $this->moduleOptions = $moduleOptions;
0 ignored issues
show
Documentation Bug introduced by
$moduleOptions is of type object<Nnx\Doctrine\Opti...ModuleOptionsInterface>, but the property $moduleOptions was declared to be of type object<Nnx\Doctrine\Options\ModuleOptions>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
125
126
        return $this;
127
    }
128
}
129