Complex classes like RelationalBuilder 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 RelationalBuilder, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
40 | class RelationalBuilder extends AbstractManagerBuilder |
||
41 | { |
||
42 | /** |
||
43 | * Query cache driver. |
||
44 | * |
||
45 | * @var CacheProvider |
||
46 | */ |
||
47 | protected $queryCacheDriver; |
||
48 | |||
49 | /** |
||
50 | * Result cache driver. |
||
51 | * |
||
52 | * @var CacheProvider |
||
53 | */ |
||
54 | protected $resultCacheDriver; |
||
55 | |||
56 | /** |
||
57 | * Hydrator cache driver. |
||
58 | * |
||
59 | * @var CacheProvider |
||
60 | */ |
||
61 | protected $hydratorCacheDriver; |
||
62 | |||
63 | /** |
||
64 | * Naming strategy. |
||
65 | * |
||
66 | * @var NamingStrategy |
||
67 | */ |
||
68 | protected $namingStrategy; |
||
69 | |||
70 | /** |
||
71 | * Quote strategy. |
||
72 | * |
||
73 | * @var QuoteStrategy |
||
74 | */ |
||
75 | protected $quoteStrategy; |
||
76 | |||
77 | /** |
||
78 | * SQL logger. |
||
79 | * |
||
80 | * @var SQLLogger |
||
81 | */ |
||
82 | protected $SQLLogger; |
||
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | protected function getDefaultOptions() |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | protected function wipe() |
||
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | * |
||
119 | * @throws \Doctrine\DBAL\DBALException |
||
120 | * @throws \Doctrine\ORM\ORMException |
||
121 | * @throws \InvalidArgumentException |
||
122 | * @throws \RuntimeException |
||
123 | * @throws \UnexpectedValueException |
||
124 | * |
||
125 | * @return EntityManager |
||
126 | */ |
||
127 | protected function buildManager() |
||
159 | |||
160 | /** |
||
161 | * Set up general manager configurations. |
||
162 | * |
||
163 | * @param Configuration $config |
||
164 | */ |
||
165 | protected function setUpGeneralConfigurations(Configuration $config) |
||
184 | |||
185 | /** |
||
186 | * Set up manager specific configurations. |
||
187 | * |
||
188 | * @param Configuration $config |
||
189 | */ |
||
190 | protected function setUpSpecificConfigurations(Configuration $config) |
||
208 | |||
209 | /** |
||
210 | * {@inheritdoc} |
||
211 | */ |
||
212 | protected function getAnnotationMappingDriver(array $paths) |
||
216 | |||
217 | /** |
||
218 | * {@inheritdoc} |
||
219 | */ |
||
220 | protected function getXmlMappingDriver(array $paths, $extension = null) |
||
226 | |||
227 | /** |
||
228 | * {@inheritdoc} |
||
229 | */ |
||
230 | protected function getYamlMappingDriver(array $paths, $extension = null) |
||
236 | |||
237 | /** |
||
238 | * {@inheritdoc} |
||
239 | * |
||
240 | * @throws \InvalidArgumentException |
||
241 | * |
||
242 | * @return RepositoryFactory|null |
||
243 | */ |
||
244 | protected function getRepositoryFactory() |
||
261 | |||
262 | /** |
||
263 | * Retrieve query cache driver. |
||
264 | * |
||
265 | * @throws \InvalidArgumentException |
||
266 | * |
||
267 | * @return CacheProvider |
||
268 | */ |
||
269 | public function getQueryCacheDriver() |
||
289 | |||
290 | /** |
||
291 | * Set query cache driver. |
||
292 | * |
||
293 | * @param CacheProvider $queryCacheDriver |
||
294 | */ |
||
295 | public function setQueryCacheDriver(CacheProvider $queryCacheDriver) |
||
299 | |||
300 | /** |
||
301 | * Retrieve result cache driver. |
||
302 | * |
||
303 | * @throws \InvalidArgumentException |
||
304 | * |
||
305 | * @return CacheProvider |
||
306 | */ |
||
307 | public function getResultCacheDriver() |
||
327 | |||
328 | /** |
||
329 | * Set result cache driver. |
||
330 | * |
||
331 | * @param CacheProvider $resultCacheDriver |
||
332 | */ |
||
333 | public function setResultCacheDriver(CacheProvider $resultCacheDriver) |
||
337 | |||
338 | /** |
||
339 | * Retrieve hydrator cache driver. |
||
340 | * |
||
341 | * @throws \InvalidArgumentException |
||
342 | * |
||
343 | * @return CacheProvider |
||
344 | */ |
||
345 | public function getHydratorCacheDriver() |
||
365 | |||
366 | /** |
||
367 | * Set hydrator cache driver. |
||
368 | * |
||
369 | * @param CacheProvider $hydratorCacheDriver |
||
370 | */ |
||
371 | public function setHydratorCacheDriver(CacheProvider $hydratorCacheDriver) |
||
375 | |||
376 | /** |
||
377 | * Retrieve naming strategy. |
||
378 | * |
||
379 | * @return NamingStrategy |
||
380 | */ |
||
381 | protected function getNamingStrategy() |
||
395 | |||
396 | /** |
||
397 | * Retrieve quote strategy. |
||
398 | * |
||
399 | * @throws \InvalidArgumentException |
||
400 | * |
||
401 | * @return QuoteStrategy |
||
402 | */ |
||
403 | protected function getQuoteStrategy() |
||
417 | |||
418 | /** |
||
419 | * Retrieve SQL logger. |
||
420 | * |
||
421 | * @return SQLLogger|null |
||
422 | */ |
||
423 | protected function getSQLLogger() |
||
435 | |||
436 | /** |
||
437 | * Retrieve custom DQL string functions. |
||
438 | * |
||
439 | * @return array |
||
440 | */ |
||
441 | protected function getCustomStringFunctions() |
||
453 | |||
454 | /** |
||
455 | * Retrieve custom DQL numeric functions. |
||
456 | * |
||
457 | * @return array |
||
458 | */ |
||
459 | protected function getCustomNumericFunctions() |
||
471 | |||
472 | /** |
||
473 | * Retrieve custom DQL date time functions. |
||
474 | * |
||
475 | * @return array |
||
476 | */ |
||
477 | protected function getCustomDateTimeFunctions() |
||
489 | |||
490 | /** |
||
491 | * Retrieve custom DBAL types. |
||
492 | * |
||
493 | * @return array |
||
494 | */ |
||
495 | protected function getCustomTypes() |
||
507 | |||
508 | /** |
||
509 | * Get custom registered filters. |
||
510 | * |
||
511 | * @return array |
||
512 | */ |
||
513 | protected function getCustomFilters() |
||
525 | |||
526 | /** |
||
527 | * {@inheritdoc} |
||
528 | * |
||
529 | * @throws \Doctrine\DBAL\DBALException |
||
530 | * @throws \Doctrine\ORM\ORMException |
||
531 | * @throws \InvalidArgumentException |
||
532 | * @throws \RuntimeException |
||
533 | * @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
||
534 | * @throws \Symfony\Component\Console\Exception\LogicException |
||
535 | * @throws \UnexpectedValueException |
||
536 | * |
||
537 | * @return Command[] |
||
538 | */ |
||
539 | public function getConsoleCommands() |
||
591 | |||
592 | /** |
||
593 | * {@inheritdoc} |
||
594 | * |
||
595 | * @throws \Doctrine\DBAL\DBALException |
||
596 | * @throws \Doctrine\ORM\ORMException |
||
597 | * @throws \InvalidArgumentException |
||
598 | * @throws \RuntimeException |
||
599 | * @throws \UnexpectedValueException |
||
600 | */ |
||
601 | public function getConsoleHelperSet() |
||
611 | } |
||
612 |