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 |
||
| 34 | class RelationalBuilder extends AbstractManagerBuilder |
||
| 35 | { |
||
| 36 | /** |
||
| 37 | * Entity Manager. |
||
| 38 | * |
||
| 39 | * @var EntityManager |
||
| 40 | */ |
||
| 41 | protected $manager; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Query cache driver. |
||
| 45 | * |
||
| 46 | * @var Cache |
||
| 47 | */ |
||
| 48 | protected $queryCacheDriver; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Result cache driver. |
||
| 52 | * |
||
| 53 | * @var Cache |
||
| 54 | */ |
||
| 55 | protected $resultCacheDriver; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Naming strategy. |
||
| 59 | * |
||
| 60 | * @var NamingStrategy |
||
| 61 | */ |
||
| 62 | protected $namingStrategy; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Quote strategy. |
||
| 66 | * |
||
| 67 | * @var QuoteStrategy |
||
| 68 | */ |
||
| 69 | protected $quoteStrategy; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * SQL logger. |
||
| 73 | * |
||
| 74 | * @var SQLLogger |
||
| 75 | */ |
||
| 76 | protected $SQLLogger; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * {@inheritdoc} |
||
| 80 | */ |
||
| 81 | protected function getDefaultOptions() |
||
| 101 | |||
| 102 | /** |
||
| 103 | * {@inheritdoc} |
||
| 104 | * |
||
| 105 | * @throws \Doctrine\DBAL\DBALException |
||
| 106 | * @throws \Doctrine\ORM\ORMException |
||
| 107 | * @throws \InvalidArgumentException |
||
| 108 | * @throws \RuntimeException |
||
| 109 | * @throws \UnexpectedValueException |
||
| 110 | * |
||
| 111 | * @return EntityManager |
||
| 112 | */ |
||
| 113 | public function getManager($standalone = false, $force = false) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * {@inheritdoc} |
||
| 128 | */ |
||
| 129 | protected function wipe() |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Build new Doctrine entity manager. |
||
| 143 | * |
||
| 144 | * @param bool $standalone |
||
| 145 | * |
||
| 146 | * @throws \Doctrine\DBAL\DBALException |
||
| 147 | * @throws \Doctrine\ORM\ORMException |
||
| 148 | * @throws \InvalidArgumentException |
||
| 149 | * @throws \RuntimeException |
||
| 150 | * @throws \UnexpectedValueException |
||
| 151 | * |
||
| 152 | * @return EntityManager |
||
| 153 | */ |
||
| 154 | protected function buildManager($standalone = false) |
||
| 191 | |||
| 192 | /** |
||
| 193 | * {@inheritdoc} |
||
| 194 | * |
||
| 195 | * @return AnnotationDriver |
||
| 196 | */ |
||
| 197 | protected function getAnnotationMetadataDriver(array $paths) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * {@inheritdoc} |
||
| 204 | * |
||
| 205 | * @return XmlDriver |
||
| 206 | */ |
||
| 207 | protected function getXmlMetadataDriver(array $paths, $extension = null) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * {@inheritdoc} |
||
| 214 | * |
||
| 215 | * @return YamlDriver |
||
| 216 | */ |
||
| 217 | protected function getYamlMetadataDriver(array $paths, $extension = null) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Retrieve query cache driver. |
||
| 224 | * |
||
| 225 | * @throws \InvalidArgumentException |
||
| 226 | * |
||
| 227 | * @return Cache |
||
| 228 | */ |
||
| 229 | public function getQueryCacheDriver() |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Set query cache driver. |
||
| 250 | * |
||
| 251 | * @param Cache $queryCacheDriver |
||
| 252 | */ |
||
| 253 | public function setQueryCacheDriver(Cache $queryCacheDriver) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Retrieve result cache driver. |
||
| 260 | * |
||
| 261 | * @throws \InvalidArgumentException |
||
| 262 | * |
||
| 263 | * @return Cache |
||
| 264 | */ |
||
| 265 | public function getResultCacheDriver() |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Set result cache driver. |
||
| 286 | * |
||
| 287 | * @param Cache $resultCacheDriver |
||
| 288 | */ |
||
| 289 | public function setResultCacheDriver(Cache $resultCacheDriver) |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Get default repository class name |
||
| 296 | * |
||
| 297 | * @return string|null |
||
| 298 | */ |
||
| 299 | protected function getDefaultRepositoryClass() |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Retrieve naming strategy. |
||
| 308 | * |
||
| 309 | * @return NamingStrategy |
||
| 310 | */ |
||
| 311 | protected function getNamingStrategy() |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Retrieve quote strategy. |
||
| 328 | * |
||
| 329 | * @throws \InvalidArgumentException |
||
| 330 | * |
||
| 331 | * @return QuoteStrategy |
||
| 332 | */ |
||
| 333 | protected function getQuoteStrategy() |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Retrieve SQL logger. |
||
| 350 | * |
||
| 351 | * @return SQLLogger|null |
||
| 352 | */ |
||
| 353 | protected function getSQLLogger() |
||
| 365 | |||
| 366 | /** |
||
| 367 | * Retrieve custom DQL string functions. |
||
| 368 | * |
||
| 369 | * @return array |
||
| 370 | */ |
||
| 371 | protected function getCustomStringFunctions() |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Retrieve custom DQL numeric functions. |
||
| 386 | * |
||
| 387 | * @return array |
||
| 388 | */ |
||
| 389 | protected function getCustomNumericFunctions() |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Retrieve custom DQL date time functions. |
||
| 404 | * |
||
| 405 | * @return array |
||
| 406 | */ |
||
| 407 | protected function getCustomDateTimeFunctions() |
||
| 419 | |||
| 420 | /** |
||
| 421 | * Retrieve custom DBAL types. |
||
| 422 | * |
||
| 423 | * @return array |
||
| 424 | */ |
||
| 425 | protected function getCustomTypes() |
||
| 437 | |||
| 438 | /** |
||
| 439 | * {@inheritdoc} |
||
| 440 | * |
||
| 441 | * @throws \Doctrine\DBAL\DBALException |
||
| 442 | * @throws \Doctrine\ORM\ORMException |
||
| 443 | * @throws \InvalidArgumentException |
||
| 444 | * @throws \RuntimeException |
||
| 445 | * @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
||
| 446 | * @throws \Symfony\Component\Console\Exception\LogicException |
||
| 447 | * @throws \UnexpectedValueException |
||
| 448 | * |
||
| 449 | * @return Command[] |
||
| 450 | */ |
||
| 451 | public function getConsoleCommands() |
||
| 499 | |||
| 500 | /** |
||
| 501 | * {@inheritdoc} |
||
| 502 | * |
||
| 503 | * @throws \Doctrine\DBAL\DBALException |
||
| 504 | * @throws \Doctrine\ORM\ORMException |
||
| 505 | * @throws \InvalidArgumentException |
||
| 506 | * @throws \RuntimeException |
||
| 507 | * @throws \UnexpectedValueException |
||
| 508 | */ |
||
| 509 | public function getConsoleHelperSet() |
||
| 518 | } |
||
| 519 |