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 |
||
35 | class RelationalBuilder extends AbstractManagerBuilder |
||
36 | { |
||
37 | /** |
||
38 | * Entity Manager. |
||
39 | * |
||
40 | * @var EntityManager |
||
41 | */ |
||
42 | protected $manager; |
||
43 | |||
44 | /** |
||
45 | * Query cache driver. |
||
46 | * |
||
47 | * @var Cache |
||
48 | */ |
||
49 | protected $queryCacheDriver; |
||
50 | |||
51 | /** |
||
52 | * Result cache driver. |
||
53 | * |
||
54 | * @var Cache |
||
55 | */ |
||
56 | protected $resultCacheDriver; |
||
57 | |||
58 | /** |
||
59 | * Naming strategy. |
||
60 | * |
||
61 | * @var NamingStrategy |
||
62 | */ |
||
63 | protected $namingStrategy; |
||
64 | |||
65 | /** |
||
66 | * Quote strategy. |
||
67 | * |
||
68 | * @var QuoteStrategy |
||
69 | */ |
||
70 | protected $quoteStrategy; |
||
71 | |||
72 | /** |
||
73 | * SQL logger. |
||
74 | * |
||
75 | * @var SQLLogger |
||
76 | */ |
||
77 | protected $SQLLogger; |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | protected function getDefaultOptions() |
||
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | * |
||
116 | * @throws \Doctrine\DBAL\DBALException |
||
117 | * @throws \Doctrine\ORM\ORMException |
||
118 | * @throws \InvalidArgumentException |
||
119 | * @throws \RuntimeException |
||
120 | * @throws \UnexpectedValueException |
||
121 | * |
||
122 | * @return EntityManager |
||
123 | */ |
||
124 | public function getManager($standalone = false, $force = false) |
||
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | */ |
||
140 | protected function wipe() |
||
151 | |||
152 | /** |
||
153 | * Build new Doctrine entity manager. |
||
154 | * |
||
155 | * @param bool $standalone |
||
156 | * |
||
157 | * @throws \Doctrine\DBAL\DBALException |
||
158 | * @throws \Doctrine\ORM\ORMException |
||
159 | * @throws \InvalidArgumentException |
||
160 | * @throws \RuntimeException |
||
161 | * @throws \UnexpectedValueException |
||
162 | * |
||
163 | * @return EntityManager |
||
164 | */ |
||
165 | protected function buildManager($standalone = false) |
||
202 | |||
203 | /** |
||
204 | * {@inheritdoc} |
||
205 | * |
||
206 | * @return AnnotationDriver |
||
207 | */ |
||
208 | protected function getAnnotationMetadataDriver(array $paths) |
||
212 | |||
213 | /** |
||
214 | * {@inheritdoc} |
||
215 | * |
||
216 | * @return XmlDriver |
||
217 | */ |
||
218 | protected function getXmlMetadataDriver(array $paths, $extension = null) |
||
222 | |||
223 | /** |
||
224 | * {@inheritdoc} |
||
225 | * |
||
226 | * @return YamlDriver |
||
227 | */ |
||
228 | protected function getYamlMetadataDriver(array $paths, $extension = null) |
||
232 | |||
233 | /** |
||
234 | * Retrieve query cache driver. |
||
235 | * |
||
236 | * @throws \InvalidArgumentException |
||
237 | * |
||
238 | * @return Cache |
||
239 | */ |
||
240 | public function getQueryCacheDriver() |
||
258 | |||
259 | /** |
||
260 | * Set query cache driver. |
||
261 | * |
||
262 | * @param Cache $queryCacheDriver |
||
263 | */ |
||
264 | public function setQueryCacheDriver(Cache $queryCacheDriver) |
||
268 | |||
269 | /** |
||
270 | * Retrieve query cache namespace. |
||
271 | * |
||
272 | * @return string |
||
273 | */ |
||
274 | protected function getQueryCacheNamespace() |
||
278 | |||
279 | /** |
||
280 | * Retrieve result cache driver. |
||
281 | * |
||
282 | * @throws \InvalidArgumentException |
||
283 | * |
||
284 | * @return Cache |
||
285 | */ |
||
286 | public function getResultCacheDriver() |
||
304 | |||
305 | /** |
||
306 | * Set result cache driver. |
||
307 | * |
||
308 | * @param Cache $resultCacheDriver |
||
309 | */ |
||
310 | public function setResultCacheDriver(Cache $resultCacheDriver) |
||
314 | |||
315 | /** |
||
316 | * Retrieve result cache namespace. |
||
317 | * |
||
318 | * @return string |
||
319 | */ |
||
320 | protected function getResultCacheNamespace() |
||
324 | |||
325 | /** |
||
326 | * Get default repository class name |
||
327 | * |
||
328 | * @return string|null |
||
329 | */ |
||
330 | protected function getDefaultRepositoryClass() |
||
336 | |||
337 | /** |
||
338 | * Retrieve naming strategy. |
||
339 | * |
||
340 | * @return NamingStrategy |
||
341 | */ |
||
342 | protected function getNamingStrategy() |
||
356 | |||
357 | /** |
||
358 | * Retrieve quote strategy. |
||
359 | * |
||
360 | * @throws \InvalidArgumentException |
||
361 | * |
||
362 | * @return QuoteStrategy |
||
363 | */ |
||
364 | protected function getQuoteStrategy() |
||
378 | |||
379 | /** |
||
380 | * Retrieve SQL logger. |
||
381 | * |
||
382 | * @return SQLLogger|null |
||
383 | */ |
||
384 | protected function getSQLLogger() |
||
396 | |||
397 | /** |
||
398 | * Retrieve custom DQL string functions. |
||
399 | * |
||
400 | * @return array |
||
401 | */ |
||
402 | protected function getCustomStringFunctions() |
||
414 | |||
415 | /** |
||
416 | * Retrieve custom DQL numeric functions. |
||
417 | * |
||
418 | * @return array |
||
419 | */ |
||
420 | protected function getCustomNumericFunctions() |
||
432 | |||
433 | /** |
||
434 | * Retrieve custom DQL date time functions. |
||
435 | * |
||
436 | * @return array |
||
437 | */ |
||
438 | protected function getCustomDateTimeFunctions() |
||
450 | |||
451 | /** |
||
452 | * Retrieve custom DBAL types. |
||
453 | * |
||
454 | * @return array |
||
455 | */ |
||
456 | protected function getCustomTypes() |
||
468 | |||
469 | /** |
||
470 | * {@inheritdoc} |
||
471 | * |
||
472 | * @throws \Doctrine\DBAL\DBALException |
||
473 | * @throws \Doctrine\ORM\ORMException |
||
474 | * @throws \InvalidArgumentException |
||
475 | * @throws \RuntimeException |
||
476 | * @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
||
477 | * @throws \Symfony\Component\Console\Exception\LogicException |
||
478 | * @throws \UnexpectedValueException |
||
479 | * |
||
480 | * @return Command[] |
||
481 | */ |
||
482 | public function getConsoleCommands() |
||
530 | |||
531 | /** |
||
532 | * {@inheritdoc} |
||
533 | * |
||
534 | * @throws \Doctrine\DBAL\DBALException |
||
535 | * @throws \Doctrine\ORM\ORMException |
||
536 | * @throws \InvalidArgumentException |
||
537 | * @throws \RuntimeException |
||
538 | * @throws \UnexpectedValueException |
||
539 | */ |
||
540 | public function getConsoleHelperSet() |
||
549 | } |
||
550 |