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 | * Retrieve naming strategy. |
||
| 327 | * |
||
| 328 | * @return NamingStrategy |
||
| 329 | */ |
||
| 330 | protected function getNamingStrategy() |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Retrieve quote strategy. |
||
| 347 | * |
||
| 348 | * @throws \InvalidArgumentException |
||
| 349 | * |
||
| 350 | * @return QuoteStrategy |
||
| 351 | */ |
||
| 352 | protected function getQuoteStrategy() |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Retrieve SQL logger. |
||
| 369 | * |
||
| 370 | * @return SQLLogger|null |
||
| 371 | */ |
||
| 372 | protected function getSQLLogger() |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Retrieve custom DQL string functions. |
||
| 387 | * |
||
| 388 | * @return array |
||
| 389 | */ |
||
| 390 | protected function getCustomStringFunctions() |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Retrieve custom DQL numeric functions. |
||
| 405 | * |
||
| 406 | * @return array |
||
| 407 | */ |
||
| 408 | protected function getCustomNumericFunctions() |
||
| 420 | |||
| 421 | /** |
||
| 422 | * Retrieve custom DQL date time functions. |
||
| 423 | * |
||
| 424 | * @return array |
||
| 425 | */ |
||
| 426 | protected function getCustomDateTimeFunctions() |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Retrieve custom DBAL types. |
||
| 441 | * |
||
| 442 | * @return array |
||
| 443 | */ |
||
| 444 | protected function getCustomTypes() |
||
| 456 | |||
| 457 | /** |
||
| 458 | * {@inheritdoc} |
||
| 459 | * |
||
| 460 | * @throws \Doctrine\DBAL\DBALException |
||
| 461 | * @throws \Doctrine\ORM\ORMException |
||
| 462 | * @throws \InvalidArgumentException |
||
| 463 | * @throws \RuntimeException |
||
| 464 | * @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
||
| 465 | * @throws \Symfony\Component\Console\Exception\LogicException |
||
| 466 | * @throws \UnexpectedValueException |
||
| 467 | * |
||
| 468 | * @return Command[] |
||
| 469 | */ |
||
| 470 | public function getConsoleCommands() |
||
| 518 | |||
| 519 | /** |
||
| 520 | * {@inheritdoc} |
||
| 521 | * |
||
| 522 | * @throws \Doctrine\DBAL\DBALException |
||
| 523 | * @throws \Doctrine\ORM\ORMException |
||
| 524 | * @throws \InvalidArgumentException |
||
| 525 | * @throws \RuntimeException |
||
| 526 | * @throws \UnexpectedValueException |
||
| 527 | */ |
||
| 528 | public function getConsoleHelperSet() |
||
| 537 | } |
||
| 538 |