CustomEntityManager   A
last analyzed

Complexity

Total Complexity 41

Size/Duplication

Total Lines 174
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 41
eloc 5
c 1
b 0
f 0
dl 0
loc 174
rs 9.1199

81 Methods

Rating   Name   Duplication   Size   Complexity  
A getCache() 0 2 1
A hp$0 ➔ contains() 0 2 1
A hp$0 ➔ __construct() 0 3 1
A hp$0 ➔ clear() 0 2 1
lock() 0 2 ?
A hp$0 ➔ getConnection() 0 14 1
A hp$0 ➔ getExpressionBuilder() 0 2 1
remove() 0 2 ?
detach() 0 2 ?
getRepository() 0 2 ?
getExpressionBuilder() 0 2 ?
A hp$0 ➔ transactional() 0 2 1
hasFilters() 0 2 ?
isFiltersStateClean() 0 2 ?
A hp$0 ➔ getRepository() 0 2 1
A hp$0 ➔ createQuery() 0 2 1
A hp$0 ➔ copy() 0 2 1
createNamedNativeQuery() 0 2 ?
newHydrator() 0 2 ?
A hp$0 ➔ createNativeQuery() 0 2 1
A hp$0 ➔ isOpen() 0 2 1
A hp$0 ➔ hasFilters() 0 2 1
getProxyFactory() 0 2 ?
transactional() 0 2 ?
getConnection() 0 14 ?
initializeObject() 0 2 ?
getPartialReference() 0 2 ?
A hp$0 ➔ getEventManager() 0 2 1
createNativeQuery() 0 2 ?
A hp$0 ➔ commit() 0 2 1
getUnitOfWork() 0 2 ?
getEventManager() 0 2 ?
createQueryBuilder() 0 2 ?
A hp$0 ➔ createQueryBuilder() 0 2 1
createQuery() 0 2 ?
find() 0 2 ?
persist() 0 2 ?
A hp$0 ➔ getEm() 0 3 1
A hp$0 ➔ getHydrator() 0 2 1
A hp$0 ➔ persist() 0 2 1
rollback() 0 2 ?
copy() 0 2 ?
A hp$0 ➔ flush() 0 2 1
createNamedQuery() 0 2 ?
A hp$0 ➔ createNamedNativeQuery() 0 2 1
A hp$0 ➔ getClassMetadata() 0 2 1
A hp$0 ➔ getReference() 0 2 1
A hp$0 ➔ lock() 0 2 1
refresh() 0 2 ?
getHydrator() 0 2 ?
contains() 0 2 ?
A hp$0 ➔ getConfiguration() 0 2 1
beginTransaction() 0 2 ?
close() 0 2 ?
A hp$0 ➔ getUnitOfWork() 0 2 1
A hp$0 ➔ rollback() 0 2 1
A hp$0 ➔ find() 0 2 1
A hp$0 ➔ detach() 0 2 1
clear() 0 2 ?
getReference() 0 2 ?
getConfiguration() 0 2 ?
getClassMetadata() 0 2 ?
A hp$0 ➔ getMetadataFactory() 0 2 1
A hp$0 ➔ getProxyFactory() 0 2 1
A hp$0 ➔ isFiltersStateClean() 0 2 1
A hp$0 ➔ newHydrator() 0 2 1
A hp$0 ➔ close() 0 2 1
A hp$0 ➔ getFilters() 0 2 1
A hp$0 ➔ merge() 0 2 1
commit() 0 2 ?
A hp$0 ➔ initializeObject() 0 2 1
merge() 0 2 ?
A hp$0 ➔ refresh() 0 2 1
A hp$0 ➔ remove() 0 2 1
A hp$0 ➔ getPartialReference() 0 2 1
A hp$0 ➔ beginTransaction() 0 2 1
getFilters() 0 2 ?
A hp$0 ➔ createNamedQuery() 0 2 1
isOpen() 0 2 ?
getMetadataFactory() 0 2 ?
flush() 0 2 ?

How to fix   Complexity   

Complex Class

Complex classes like CustomEntityManager often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use CustomEntityManager, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Bundle\MigrationsBundle\Tests\Fixtures;
6
7
use Doctrine\DBAL\Connection;
8
use Doctrine\ORM\EntityManagerInterface;
9
use Doctrine\ORM\Query\ResultSetMapping;
10
11
class CustomEntityManager implements EntityManagerInterface
12
{
13
    public function getCache() : void
14
    {
15
    }
16
17
    public function getConnection()
18
    {
19
        return new class ($this) extends Connection {
20
            /** @var CustomEntityManager */
21
            private $em;
22
23
            public function __construct(CustomEntityManager $em)
24
            {
25
                $this->em = $em;
26
            }
27
28
            public function getEm()
29
            {
30
                return $this->em;
31
            }
32
        };
33
    }
34
35
    public function getExpressionBuilder() : void
36
    {
37
    }
38
39
    public function beginTransaction() : void
40
    {
41
    }
42
43
    public function transactional($func) : void
44
    {
45
    }
46
47
    public function commit() : void
48
    {
49
    }
50
51
    public function rollback() : void
52
    {
53
    }
54
55
    public function createQuery($dql = '') : void
56
    {
57
    }
58
59
    public function createNamedQuery($name) : void
60
    {
61
    }
62
63
    public function createNativeQuery($sql, ResultSetMapping $rsm) : void
64
    {
65
    }
66
67
    public function createNamedNativeQuery($name) : void
68
    {
69
    }
70
71
    public function createQueryBuilder() : void
72
    {
73
    }
74
75
    public function getReference($entityName, $id) : void
76
    {
77
    }
78
79
    public function getPartialReference($entityName, $identifier) : void
80
    {
81
    }
82
83
    public function close() : void
84
    {
85
    }
86
87
    public function copy($entity, $deep = false) : void
88
    {
89
    }
90
91
    public function lock($entity, $lockMode, $lockVersion = null) : void
92
    {
93
    }
94
95
    public function getEventManager() : void
96
    {
97
    }
98
99
    public function getConfiguration() : void
100
    {
101
    }
102
103
    public function isOpen() : void
104
    {
105
    }
106
107
    public function getUnitOfWork() : void
108
    {
109
    }
110
111
    public function getHydrator($hydrationMode) : void
112
    {
113
    }
114
115
    public function newHydrator($hydrationMode) : void
116
    {
117
    }
118
119
    public function getProxyFactory() : void
120
    {
121
    }
122
123
    public function getFilters() : void
124
    {
125
    }
126
127
    public function isFiltersStateClean() : void
128
    {
129
    }
130
131
    public function hasFilters() : void
132
    {
133
    }
134
135
    public function find($className, $id) : void
136
    {
137
    }
138
139
    public function persist($object) : void
140
    {
141
    }
142
143
    public function remove($object) : void
144
    {
145
    }
146
147
    public function merge($object) : void
148
    {
149
    }
150
151
    public function clear($objectName = null) : void
152
    {
153
    }
154
155
    public function detach($object) : void
156
    {
157
    }
158
159
    public function refresh($object) : void
160
    {
161
    }
162
163
    public function flush() : void
164
    {
165
    }
166
167
    public function getRepository($className) : void
168
    {
169
    }
170
171
    public function getMetadataFactory() : void
172
    {
173
    }
174
175
    public function initializeObject($obj) : void
176
    {
177
    }
178
179
    public function contains($object) : void
180
    {
181
    }
182
183
    public function getClassMetadata($className) : void
184
    {
185
    }
186
}
187