Complex classes like MongoDBBuilder 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 MongoDBBuilder, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
31 | class MongoDBBuilder extends AbstractManagerBuilder |
||
32 | { |
||
33 | /** |
||
34 | * Document Manager. |
||
35 | * |
||
36 | * @var DocumentManager |
||
37 | */ |
||
38 | protected $manager; |
||
39 | |||
40 | /** |
||
41 | * Logger callable. |
||
42 | * |
||
43 | * @var callable |
||
44 | */ |
||
45 | protected $loggerCallable; |
||
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | protected function getDefaultOptions() |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | * |
||
67 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
68 | * @throws \InvalidArgumentException |
||
69 | * @throws \RuntimeException |
||
70 | * @throws \UnexpectedValueException |
||
71 | * |
||
72 | * @return DocumentManager |
||
73 | */ |
||
74 | public function getManager($force = false) |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | protected function wipe() |
||
97 | |||
98 | /** |
||
99 | * Build Doctrine MongoDB Document Manager. |
||
100 | * |
||
101 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
102 | * @throws \InvalidArgumentException |
||
103 | * @throws \RuntimeException |
||
104 | * @throws \UnexpectedValueException |
||
105 | * |
||
106 | * @return DocumentManager |
||
107 | */ |
||
108 | protected function buildManager() |
||
127 | |||
128 | /** |
||
129 | * Set up general manager configurations. |
||
130 | * |
||
131 | * @param Configuration $config |
||
132 | */ |
||
133 | protected function setUpGeneralConfigurations(Configuration $config) |
||
152 | |||
153 | /** |
||
154 | * Set up manager specific configurations. |
||
155 | * |
||
156 | * @param Configuration $config |
||
157 | */ |
||
158 | protected function setUpSpecificConfigurations(Configuration $config) |
||
180 | |||
181 | /** |
||
182 | * Create MongoDB Connection. |
||
183 | * |
||
184 | * @param Configuration $config |
||
185 | * |
||
186 | * @throws \InvalidArgumentException |
||
187 | * @throws \RuntimeException |
||
188 | * |
||
189 | * @return Connection |
||
190 | */ |
||
191 | protected function getConnection(Configuration $config) |
||
219 | |||
220 | /** |
||
221 | * {@inheritdoc} |
||
222 | */ |
||
223 | protected function getAnnotationMappingDriver(array $paths) |
||
227 | |||
228 | /** |
||
229 | * {@inheritdoc} |
||
230 | */ |
||
231 | protected function getXmlMappingDriver(array $paths, $extension = null) |
||
237 | |||
238 | /** |
||
239 | * {@inheritdoc} |
||
240 | */ |
||
241 | protected function getYamlMappingDriver(array $paths, $extension = null) |
||
247 | |||
248 | /** |
||
249 | * {@inheritdoc} |
||
250 | * |
||
251 | * @throws \InvalidArgumentException |
||
252 | * |
||
253 | * @return RepositoryFactory|null |
||
254 | */ |
||
255 | protected function getRepositoryFactory() |
||
272 | |||
273 | /** |
||
274 | * Retrieve hydrators path. |
||
275 | * |
||
276 | * @return string |
||
277 | */ |
||
278 | protected function getHydratorsPath() |
||
282 | |||
283 | /** |
||
284 | * Retrieve hydrators namespace. |
||
285 | * |
||
286 | * @return null|string |
||
287 | */ |
||
288 | protected function getHydratorsNamespace() |
||
294 | |||
295 | /** |
||
296 | * Retrieve hydrators generation strategy. |
||
297 | * |
||
298 | * @return int |
||
299 | */ |
||
300 | protected function getHydratorsAutoGeneration() |
||
304 | |||
305 | /** |
||
306 | * Retrieve persistent collections path. |
||
307 | * |
||
308 | * @return string |
||
309 | */ |
||
310 | protected function getPersistentCollectionPath() |
||
314 | |||
315 | /** |
||
316 | * Retrieve persistent collections namespace. |
||
317 | * |
||
318 | * @return null|string |
||
319 | */ |
||
320 | protected function getPersistentCollectionNamespace() |
||
326 | |||
327 | /** |
||
328 | * Retrieve persistent collections generation strategy. |
||
329 | * |
||
330 | * @return int |
||
331 | */ |
||
332 | protected function getAutoGeneratePersistentCollection() |
||
336 | |||
337 | /** |
||
338 | * Get default database. |
||
339 | * |
||
340 | * @return string|null |
||
341 | */ |
||
342 | protected function getDefaultDatabase() |
||
346 | |||
347 | /** |
||
348 | * Retrieve logger callable. |
||
349 | * |
||
350 | * @return callable|null |
||
351 | */ |
||
352 | protected function getLoggerCallable() |
||
364 | |||
365 | /** |
||
366 | * Get custom registered filters. |
||
367 | * |
||
368 | * @return array |
||
369 | */ |
||
370 | protected function getCustomFilters() |
||
382 | |||
383 | /** |
||
384 | * {@inheritdoc} |
||
385 | * |
||
386 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
387 | * @throws \InvalidArgumentException |
||
388 | * @throws \RuntimeException |
||
389 | * @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
||
390 | * @throws \Symfony\Component\Console\Exception\LogicException |
||
391 | * @throws \UnexpectedValueException |
||
392 | * |
||
393 | * @return Command[] |
||
394 | */ |
||
395 | public function getConsoleCommands() |
||
432 | |||
433 | /** |
||
434 | * {@inheritdoc} |
||
435 | * |
||
436 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
437 | * @throws \InvalidArgumentException |
||
438 | * @throws \RuntimeException |
||
439 | * @throws \UnexpectedValueException |
||
440 | */ |
||
441 | public function getConsoleHelperSet() |
||
447 | } |
||
448 |