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 |
||
| 42 | class RelationalBuilder extends AbstractManagerBuilder |
||
| 43 | { |
||
| 44 | /** |
||
| 45 | * Query cache driver. |
||
| 46 | * |
||
| 47 | * @var CacheProvider |
||
| 48 | */ |
||
| 49 | protected $queryCacheDriver; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Result cache driver. |
||
| 53 | * |
||
| 54 | * @var CacheProvider |
||
| 55 | */ |
||
| 56 | protected $resultCacheDriver; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Hydrator cache driver. |
||
| 60 | * |
||
| 61 | * @var CacheProvider |
||
| 62 | */ |
||
| 63 | protected $hydratorCacheDriver; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Naming strategy. |
||
| 67 | * |
||
| 68 | * @var NamingStrategy |
||
| 69 | */ |
||
| 70 | protected $namingStrategy; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Quote strategy. |
||
| 74 | * |
||
| 75 | * @var QuoteStrategy |
||
| 76 | */ |
||
| 77 | protected $quoteStrategy; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Second level cache configuration. |
||
| 81 | * |
||
| 82 | * @var CacheConfiguration |
||
| 83 | */ |
||
| 84 | protected $secondCacheConfig; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * SQL logger. |
||
| 88 | * |
||
| 89 | * @var SQLLogger |
||
| 90 | */ |
||
| 91 | protected $SQLLogger; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * {@inheritdoc} |
||
| 95 | */ |
||
| 96 | protected function getDefaultOptions() |
||
| 109 | |||
| 110 | /** |
||
| 111 | * {@inheritdoc} |
||
| 112 | */ |
||
| 113 | protected function wipe() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * {@inheritdoc} |
||
| 128 | * |
||
| 129 | * @throws \Doctrine\DBAL\DBALException |
||
| 130 | * @throws \Doctrine\ORM\ORMException |
||
| 131 | * @throws \InvalidArgumentException |
||
| 132 | * @throws \RuntimeException |
||
| 133 | * @throws \UnexpectedValueException |
||
| 134 | * |
||
| 135 | * @return EntityManager |
||
| 136 | */ |
||
| 137 | protected function buildManager() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Set up general manager configurations. |
||
| 172 | * |
||
| 173 | * @param Configuration $config |
||
| 174 | */ |
||
| 175 | protected function setUpGeneralConfigurations(Configuration $config) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Set up manager specific configurations. |
||
| 197 | * |
||
| 198 | * @param Configuration $config |
||
| 199 | */ |
||
| 200 | protected function setUpSpecificConfigurations(Configuration $config) |
||
| 223 | |||
| 224 | /** |
||
| 225 | * {@inheritdoc} |
||
| 226 | */ |
||
| 227 | protected function getAnnotationMappingDriver(array $paths) |
||
| 231 | |||
| 232 | /** |
||
| 233 | * {@inheritdoc} |
||
| 234 | */ |
||
| 235 | protected function getXmlMappingDriver(array $paths, $extension = null) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * {@inheritdoc} |
||
| 244 | */ |
||
| 245 | protected function getYamlMappingDriver(array $paths, $extension = null) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * {@inheritdoc} |
||
| 254 | * |
||
| 255 | * @throws \InvalidArgumentException |
||
| 256 | * |
||
| 257 | * @return RepositoryFactory|null |
||
| 258 | */ |
||
| 259 | protected function getRepositoryFactory() |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Retrieve query cache driver. |
||
| 279 | * |
||
| 280 | * @throws \InvalidArgumentException |
||
| 281 | * |
||
| 282 | * @return CacheProvider |
||
| 283 | */ |
||
| 284 | public function getQueryCacheDriver() |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Set query cache driver. |
||
| 298 | * |
||
| 299 | * @param CacheProvider $queryCacheDriver |
||
| 300 | */ |
||
| 301 | public function setQueryCacheDriver(CacheProvider $queryCacheDriver) |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Retrieve result cache driver. |
||
| 308 | * |
||
| 309 | * @throws \InvalidArgumentException |
||
| 310 | * |
||
| 311 | * @return CacheProvider |
||
| 312 | */ |
||
| 313 | public function getResultCacheDriver() |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Set result cache driver. |
||
| 327 | * |
||
| 328 | * @param CacheProvider $resultCacheDriver |
||
| 329 | */ |
||
| 330 | public function setResultCacheDriver(CacheProvider $resultCacheDriver) |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Retrieve hydrator cache driver. |
||
| 337 | * |
||
| 338 | * @throws \InvalidArgumentException |
||
| 339 | * |
||
| 340 | * @return CacheProvider |
||
| 341 | */ |
||
| 342 | public function getHydratorCacheDriver() |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Set hydrator cache driver. |
||
| 356 | * |
||
| 357 | * @param CacheProvider $hydratorCacheDriver |
||
| 358 | */ |
||
| 359 | public function setHydratorCacheDriver(CacheProvider $hydratorCacheDriver) |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Get cache driver. |
||
| 366 | * |
||
| 367 | * @param string $cacheNamespace |
||
| 368 | * @param CacheProvider|null $cacheDriver |
||
| 369 | * |
||
| 370 | * @return CacheProvider |
||
| 371 | */ |
||
| 372 | protected function getCacheDriver($cacheNamespace, CacheProvider $cacheDriver = null) |
||
| 385 | |||
| 386 | /** |
||
| 387 | * Retrieve naming strategy. |
||
| 388 | * |
||
| 389 | * @return NamingStrategy |
||
| 390 | */ |
||
| 391 | protected function getNamingStrategy() |
||
| 405 | |||
| 406 | /** |
||
| 407 | * Retrieve quote strategy. |
||
| 408 | * |
||
| 409 | * @throws \InvalidArgumentException |
||
| 410 | * |
||
| 411 | * @return QuoteStrategy |
||
| 412 | */ |
||
| 413 | protected function getQuoteStrategy() |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Retrieve second level cache configuration. |
||
| 430 | * |
||
| 431 | * @return CacheConfiguration|null |
||
| 432 | */ |
||
| 433 | protected function getSecondLevelCacheConfiguration() |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Retrieve SQL logger. |
||
| 448 | * |
||
| 449 | * @return SQLLogger|null |
||
| 450 | */ |
||
| 451 | protected function getSQLLogger() |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Retrieve custom DQL string functions. |
||
| 466 | * |
||
| 467 | * @return array |
||
| 468 | */ |
||
| 469 | protected function getCustomStringFunctions() |
||
| 481 | |||
| 482 | /** |
||
| 483 | * Retrieve custom DQL numeric functions. |
||
| 484 | * |
||
| 485 | * @return array |
||
| 486 | */ |
||
| 487 | protected function getCustomNumericFunctions() |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Retrieve custom DQL date time functions. |
||
| 502 | * |
||
| 503 | * @return array |
||
| 504 | */ |
||
| 505 | protected function getCustomDateTimeFunctions() |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Retrieve custom DBAL types. |
||
| 520 | * |
||
| 521 | * @return array |
||
| 522 | */ |
||
| 523 | protected function getCustomTypes() |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Get custom registered filters. |
||
| 538 | * |
||
| 539 | * @return array |
||
| 540 | */ |
||
| 541 | protected function getCustomFilters() |
||
| 553 | |||
| 554 | /** |
||
| 555 | * {@inheritdoc} |
||
| 556 | * |
||
| 557 | * @throws \Doctrine\DBAL\DBALException |
||
| 558 | * @throws \Doctrine\ORM\ORMException |
||
| 559 | * @throws \InvalidArgumentException |
||
| 560 | * @throws \RuntimeException |
||
| 561 | * @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
||
| 562 | * @throws \Symfony\Component\Console\Exception\LogicException |
||
| 563 | * @throws \UnexpectedValueException |
||
| 564 | * |
||
| 565 | * @return Command[] |
||
| 566 | */ |
||
| 567 | public function getConsoleCommands() |
||
| 619 | |||
| 620 | /** |
||
| 621 | * {@inheritdoc} |
||
| 622 | * |
||
| 623 | * @throws \Doctrine\DBAL\DBALException |
||
| 624 | * @throws \Doctrine\ORM\ORMException |
||
| 625 | * @throws \InvalidArgumentException |
||
| 626 | * @throws \RuntimeException |
||
| 627 | * @throws \UnexpectedValueException |
||
| 628 | */ |
||
| 629 | public function getConsoleHelperSet() |
||
| 639 | } |
||
| 640 |