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 |
||
34 | class MongoDBBuilder extends AbstractManagerBuilder |
||
35 | { |
||
36 | /** |
||
37 | * Logger callable. |
||
38 | * |
||
39 | * @var callable |
||
40 | */ |
||
41 | protected $loggerCallable; |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | protected function getDefaultOptions() |
||
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | protected function wipe() |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | * |
||
75 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
76 | * @throws \InvalidArgumentException |
||
77 | * @throws \RuntimeException |
||
78 | * @throws \UnexpectedValueException |
||
79 | * |
||
80 | * @return DocumentManager |
||
81 | */ |
||
82 | protected function buildManager() |
||
101 | |||
102 | /** |
||
103 | * Set up general manager configurations. |
||
104 | * |
||
105 | * @param Configuration $config |
||
106 | */ |
||
107 | protected function setUpGeneralConfigurations(Configuration $config) |
||
126 | |||
127 | /** |
||
128 | * Set up manager specific configurations. |
||
129 | * |
||
130 | * @param Configuration $config |
||
131 | */ |
||
132 | protected function setUpSpecificConfigurations(Configuration $config) |
||
162 | |||
163 | /** |
||
164 | * Create MongoDB Connection. |
||
165 | * |
||
166 | * @param Configuration $config |
||
167 | * |
||
168 | * @throws \InvalidArgumentException |
||
169 | * @throws \RuntimeException |
||
170 | * |
||
171 | * @return Connection |
||
172 | */ |
||
173 | protected function getConnection(Configuration $config) |
||
201 | |||
202 | /** |
||
203 | * {@inheritdoc} |
||
204 | */ |
||
205 | protected function getAnnotationMappingDriver(array $paths) |
||
209 | |||
210 | /** |
||
211 | * {@inheritdoc} |
||
212 | */ |
||
213 | protected function getXmlMappingDriver(array $paths, $extension = null) |
||
219 | |||
220 | /** |
||
221 | * {@inheritdoc} |
||
222 | */ |
||
223 | protected function getYamlMappingDriver(array $paths, $extension = null) |
||
229 | |||
230 | /** |
||
231 | * {@inheritdoc} |
||
232 | * |
||
233 | * @throws \InvalidArgumentException |
||
234 | * |
||
235 | * @return RepositoryFactory|null |
||
236 | */ |
||
237 | protected function getRepositoryFactory() |
||
254 | |||
255 | /** |
||
256 | * Retrieve hydrators path. |
||
257 | * |
||
258 | * @return string |
||
259 | */ |
||
260 | protected function getHydratorsPath() |
||
264 | |||
265 | /** |
||
266 | * Retrieve hydrators namespace. |
||
267 | * |
||
268 | * @return null|string |
||
269 | */ |
||
270 | protected function getHydratorsNamespace() |
||
276 | |||
277 | /** |
||
278 | * Retrieve hydrators generation strategy. |
||
279 | * |
||
280 | * @return int |
||
281 | */ |
||
282 | protected function getHydratorsAutoGeneration() |
||
286 | |||
287 | /** |
||
288 | * Retrieve persistent collections path. |
||
289 | * |
||
290 | * @return string |
||
291 | */ |
||
292 | protected function getPersistentCollectionPath() |
||
296 | |||
297 | /** |
||
298 | * Retrieve persistent collections namespace. |
||
299 | * |
||
300 | * @return null|string |
||
301 | */ |
||
302 | protected function getPersistentCollectionNamespace() |
||
308 | |||
309 | /** |
||
310 | * Retrieve persistent collections generation strategy. |
||
311 | * |
||
312 | * @return int |
||
313 | */ |
||
314 | protected function getAutoGeneratePersistentCollection() |
||
318 | |||
319 | /** |
||
320 | * Get default database. |
||
321 | * |
||
322 | * @return string|null |
||
323 | */ |
||
324 | protected function getDefaultDatabase() |
||
328 | |||
329 | /** |
||
330 | * Retrieve logger callable. |
||
331 | * |
||
332 | * @return callable|null |
||
333 | */ |
||
334 | protected function getLoggerCallable() |
||
346 | |||
347 | /** |
||
348 | * Retrieve custom types. |
||
349 | * |
||
350 | * @return array |
||
351 | */ |
||
352 | protected function getCustomTypes() |
||
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() |
||
440 | |||
441 | /** |
||
442 | * Get console helper set. |
||
443 | * |
||
444 | * @return \Symfony\Component\Console\Helper\HelperSet |
||
445 | */ |
||
446 | protected function getConsoleHelperSet() |
||
455 | } |
||
456 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.