Complex classes like FakeEntityManager 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 FakeEntityManager, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class FakeEntityManager implements EntityManagerInterface |
||
22 | { |
||
23 | use NotCallableTrait; |
||
24 | |||
25 | /** |
||
26 | * @inheritdoc |
||
27 | */ |
||
28 | public function getCache() |
||
32 | |||
33 | /** |
||
34 | * @inheritdoc |
||
35 | */ |
||
36 | public function getConnection() |
||
40 | |||
41 | /** |
||
42 | * @inheritdoc |
||
43 | */ |
||
44 | public function getExpressionBuilder() |
||
48 | |||
49 | /** |
||
50 | * @inheritdoc |
||
51 | */ |
||
52 | public function beginTransaction() |
||
56 | |||
57 | /** |
||
58 | * @inheritdoc |
||
59 | */ |
||
60 | public function transactional($func) |
||
64 | |||
65 | /** |
||
66 | * @inheritdoc |
||
67 | */ |
||
68 | public function commit() |
||
72 | |||
73 | /** |
||
74 | * @inheritdoc |
||
75 | */ |
||
76 | public function rollback() |
||
80 | |||
81 | /** |
||
82 | * @inheritdoc |
||
83 | */ |
||
84 | public function createQuery($dql = '') |
||
88 | |||
89 | /** |
||
90 | * @inheritdoc |
||
91 | */ |
||
92 | public function createNamedQuery($name) |
||
96 | |||
97 | /** |
||
98 | * @inheritdoc |
||
99 | */ |
||
100 | public function createNativeQuery($sql, ResultSetMapping $rsm) |
||
104 | |||
105 | /** |
||
106 | * @inheritdoc |
||
107 | */ |
||
108 | public function createNamedNativeQuery($name) |
||
112 | |||
113 | /** |
||
114 | * @inheritdoc |
||
115 | */ |
||
116 | public function createQueryBuilder() |
||
120 | |||
121 | /** |
||
122 | * @inheritdoc |
||
123 | */ |
||
124 | public function getReference($entityName, $id) |
||
128 | |||
129 | /** |
||
130 | * @inheritdoc |
||
131 | */ |
||
132 | public function getPartialReference($entityName, $identifier) |
||
136 | |||
137 | /** |
||
138 | * @inheritdoc |
||
139 | */ |
||
140 | public function close() |
||
144 | |||
145 | /** |
||
146 | * @inheritdoc |
||
147 | */ |
||
148 | public function copy($entity, $deep = false) |
||
152 | |||
153 | /** |
||
154 | * @inheritdoc |
||
155 | */ |
||
156 | public function lock($entity, $lockMode, $lockVersion = null) |
||
160 | |||
161 | /** |
||
162 | * @inheritdoc |
||
163 | */ |
||
164 | public function getEventManager() |
||
168 | |||
169 | /** |
||
170 | * @inheritdoc |
||
171 | */ |
||
172 | public function getConfiguration() |
||
176 | |||
177 | /** |
||
178 | * @inheritdoc |
||
179 | */ |
||
180 | public function isOpen() |
||
184 | |||
185 | /** |
||
186 | * @inheritdoc |
||
187 | */ |
||
188 | public function getUnitOfWork() |
||
192 | |||
193 | /** |
||
194 | * @inheritdoc |
||
195 | */ |
||
196 | public function getHydrator($hydrationMode) |
||
200 | |||
201 | /** |
||
202 | * @inheritdoc |
||
203 | */ |
||
204 | public function newHydrator($hydrationMode) |
||
208 | |||
209 | /** |
||
210 | * @inheritdoc |
||
211 | */ |
||
212 | public function getProxyFactory() |
||
216 | |||
217 | /** |
||
218 | * @inheritdoc |
||
219 | */ |
||
220 | public function getFilters() |
||
224 | |||
225 | /** |
||
226 | * @inheritdoc |
||
227 | */ |
||
228 | public function isFiltersStateClean() |
||
232 | |||
233 | /** |
||
234 | * @inheritdoc |
||
235 | */ |
||
236 | public function hasFilters() |
||
240 | |||
241 | /** |
||
242 | * @inheritdoc |
||
243 | */ |
||
244 | public function find($className, $id) |
||
248 | |||
249 | /** |
||
250 | * @inheritdoc |
||
251 | */ |
||
252 | public function persist($object) |
||
256 | |||
257 | /** |
||
258 | * @inheritdoc |
||
259 | */ |
||
260 | public function remove($object) |
||
264 | |||
265 | /** |
||
266 | * @inheritdoc |
||
267 | */ |
||
268 | public function merge($object) |
||
272 | |||
273 | /** |
||
274 | * @inheritdoc |
||
275 | */ |
||
276 | public function clear($objectName = null) |
||
280 | |||
281 | /** |
||
282 | * @inheritdoc |
||
283 | */ |
||
284 | public function detach($object) |
||
288 | |||
289 | /** |
||
290 | * @inheritdoc |
||
291 | */ |
||
292 | public function refresh($object) |
||
296 | |||
297 | /** |
||
298 | * @inheritdoc |
||
299 | */ |
||
300 | public function flush() |
||
304 | |||
305 | /** |
||
306 | * @inheritdoc |
||
307 | */ |
||
308 | public function getRepository($className) |
||
312 | |||
313 | /** |
||
314 | * @inheritdoc |
||
315 | */ |
||
316 | public function getMetadataFactory() |
||
320 | |||
321 | /** |
||
322 | * @inheritdoc |
||
323 | */ |
||
324 | public function initializeObject($obj) |
||
328 | |||
329 | /** |
||
330 | * @inheritdoc |
||
331 | */ |
||
332 | public function contains($object) |
||
336 | |||
337 | /** |
||
338 | * @inheritdoc |
||
339 | */ |
||
340 | public function getClassMetadata($className) |
||
344 | } |
||
345 |