Total Complexity | 40 |
Total Lines | 203 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
Complex classes like EntityManagerDecorator 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 EntityManagerDecorator, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class EntityManagerDecorator implements EntityManagerInterface |
||
20 | { |
||
21 | |||
22 | public function __construct( |
||
23 | private EntityManagerInterface $inner, |
||
24 | private DataLoaderInterface $dataLoader |
||
25 | ) { |
||
26 | $dataLoader->boot($inner); |
||
27 | } |
||
28 | |||
29 | public function getCache() |
||
30 | { |
||
31 | return $this->inner->getCache(); |
||
32 | } |
||
33 | |||
34 | public function getConnection() |
||
35 | { |
||
36 | return $this->inner->getConnection(); |
||
37 | } |
||
38 | |||
39 | public function getExpressionBuilder() |
||
40 | { |
||
41 | return $this->inner->getExpressionBuilder(); |
||
42 | } |
||
43 | |||
44 | public function beginTransaction() |
||
45 | { |
||
46 | return $this->inner->beginTransaction(); |
||
|
|||
47 | } |
||
48 | |||
49 | public function transactional($func) |
||
50 | { |
||
51 | return $this->inner->transactional($func); |
||
52 | } |
||
53 | |||
54 | public function commit() |
||
55 | { |
||
56 | return $this->inner->commit(); |
||
57 | } |
||
58 | |||
59 | public function rollback() |
||
60 | { |
||
61 | return $this->inner->rollback(); |
||
62 | } |
||
63 | |||
64 | public function createQuery($dql = '') |
||
65 | { |
||
66 | return $this->inner->createQuery($dql); |
||
67 | } |
||
68 | |||
69 | public function createNamedQuery($name) |
||
70 | { |
||
71 | return $this->inner->createNamedQuery($name); |
||
72 | } |
||
73 | |||
74 | public function createNativeQuery($sql, ResultSetMapping $rsm) |
||
75 | { |
||
76 | return $this->inner->createNativeQuery($sql, $rsm); |
||
77 | } |
||
78 | |||
79 | public function createNamedNativeQuery($name) |
||
80 | { |
||
81 | return $this->inner->createNamedNativeQuery($name); |
||
82 | } |
||
83 | |||
84 | public function createQueryBuilder() |
||
85 | { |
||
86 | return $this->inner->createQueryBuilder(); |
||
87 | } |
||
88 | |||
89 | public function getReference($entityName, $id) |
||
90 | { |
||
91 | return $this->inner->getReference($entityName, $id); |
||
92 | } |
||
93 | |||
94 | public function getPartialReference($entityName, $identifier) |
||
95 | { |
||
96 | return $this->inner->getPartialReference($entityName, $identifier); |
||
97 | } |
||
98 | |||
99 | public function close() |
||
100 | { |
||
101 | return $this->inner->close(); |
||
102 | } |
||
103 | |||
104 | public function copy($entity, $deep = false) |
||
105 | { |
||
106 | return $this->inner->copy($entity, $deep); |
||
107 | } |
||
108 | |||
109 | public function lock($entity, $lockMode, $lockVersion = null) |
||
110 | { |
||
111 | return $this->inner->lock($entity, $lockMode, $lockVersion); |
||
112 | } |
||
113 | |||
114 | public function getEventManager() |
||
115 | { |
||
116 | return $this->inner->getEventManager(); |
||
117 | } |
||
118 | |||
119 | public function getConfiguration() |
||
120 | { |
||
121 | return $this->inner->getConfiguration(); |
||
122 | } |
||
123 | |||
124 | public function isOpen() |
||
125 | { |
||
126 | return $this->inner->isOpen(); |
||
127 | } |
||
128 | |||
129 | public function getUnitOfWork() |
||
130 | { |
||
131 | return $this->inner->getUnitOfWork(); |
||
132 | } |
||
133 | |||
134 | public function getHydrator($hydrationMode) |
||
135 | { |
||
136 | return $this->inner->getHydrator($hydrationMode); |
||
137 | } |
||
138 | |||
139 | public function newHydrator($hydrationMode) |
||
140 | { |
||
141 | return $this->inner->newHydrator($hydrationMode); |
||
142 | } |
||
143 | |||
144 | public function getProxyFactory() |
||
145 | { |
||
146 | return $this->inner->getProxyFactory(); |
||
147 | } |
||
148 | |||
149 | public function getFilters() |
||
150 | { |
||
151 | return $this->inner->getFilters(); |
||
152 | } |
||
153 | |||
154 | public function isFiltersStateClean() |
||
155 | { |
||
156 | return $this->inner->isFiltersStateClean(); |
||
157 | } |
||
158 | |||
159 | public function hasFilters() |
||
160 | { |
||
161 | return $this->inner->hasFilters(); |
||
162 | } |
||
163 | |||
164 | public function find(string $className, $id) |
||
165 | { |
||
166 | return $this->inner->find($className, $id); |
||
167 | } |
||
168 | |||
169 | public function persist(object $object) |
||
170 | { |
||
171 | return $this->inner->persist($object); |
||
172 | } |
||
173 | |||
174 | public function remove(object $object) |
||
175 | { |
||
176 | return $this->inner->remove($object); |
||
177 | } |
||
178 | |||
179 | public function clear() |
||
180 | { |
||
181 | return $this->inner->clear(); |
||
182 | } |
||
183 | |||
184 | public function detach(object $object) |
||
185 | { |
||
186 | return $this->inner->detach($object); |
||
187 | } |
||
188 | |||
189 | public function refresh(object $object) |
||
192 | } |
||
193 | |||
194 | public function flush() |
||
195 | { |
||
196 | return $this->inner->flush(); |
||
197 | } |
||
198 | |||
199 | public function getRepository($className) |
||
200 | { |
||
201 | return $this->inner->getRepository($className); |
||
202 | } |
||
203 | |||
204 | public function getClassMetadata($className) |
||
205 | { |
||
206 | return $this->inner->getClassMetadata($className); |
||
207 | } |
||
208 | |||
209 | public function getMetadataFactory() |
||
212 | } |
||
213 | |||
214 | public function initializeObject(object $obj) |
||
215 | { |
||
216 | return $this->inner->initializeObject($obj); |
||
217 | } |
||
218 | |||
219 | public function contains(object $object) |
||
220 | { |
||
221 | return $this->inner->contains($object); |
||
222 | } |
||
223 | } |
||
224 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.