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 |
||
| 41 | class RelationalBuilder extends AbstractManagerBuilder |
||
| 42 | { |
||
| 43 | /** |
||
| 44 | * Query cache driver. |
||
| 45 | * |
||
| 46 | * @var CacheProvider |
||
| 47 | */ |
||
| 48 | protected $queryCacheDriver; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Result cache driver. |
||
| 52 | * |
||
| 53 | * @var CacheProvider |
||
| 54 | */ |
||
| 55 | protected $resultCacheDriver; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Hydrator cache driver. |
||
| 59 | * |
||
| 60 | * @var CacheProvider |
||
| 61 | */ |
||
| 62 | protected $hydratorCacheDriver; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Naming strategy. |
||
| 66 | * |
||
| 67 | * @var NamingStrategy |
||
| 68 | */ |
||
| 69 | protected $namingStrategy; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Quote strategy. |
||
| 73 | * |
||
| 74 | * @var QuoteStrategy |
||
| 75 | */ |
||
| 76 | protected $quoteStrategy; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * SQL logger. |
||
| 80 | * |
||
| 81 | * @var SQLLogger |
||
| 82 | */ |
||
| 83 | protected $SQLLogger; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * {@inheritdoc} |
||
| 87 | */ |
||
| 88 | protected function getDefaultOptions() |
||
| 100 | |||
| 101 | /** |
||
| 102 | * {@inheritdoc} |
||
| 103 | */ |
||
| 104 | protected function wipe() |
||
| 116 | |||
| 117 | /** |
||
| 118 | * {@inheritdoc} |
||
| 119 | * |
||
| 120 | * @throws \Doctrine\DBAL\DBALException |
||
| 121 | * @throws \Doctrine\ORM\ORMException |
||
| 122 | * @throws \InvalidArgumentException |
||
| 123 | * @throws \RuntimeException |
||
| 124 | * @throws \UnexpectedValueException |
||
| 125 | * |
||
| 126 | * @return EntityManager |
||
| 127 | */ |
||
| 128 | protected function buildManager() |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Set up general manager configurations. |
||
| 163 | * |
||
| 164 | * @param Configuration $config |
||
| 165 | */ |
||
| 166 | protected function setUpGeneralConfigurations(Configuration $config) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Set up manager specific configurations. |
||
| 188 | * |
||
| 189 | * @param Configuration $config |
||
| 190 | */ |
||
| 191 | protected function setUpSpecificConfigurations(Configuration $config) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * {@inheritdoc} |
||
| 212 | */ |
||
| 213 | protected function getAnnotationMappingDriver(array $paths) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * {@inheritdoc} |
||
| 220 | */ |
||
| 221 | protected function getXmlMappingDriver(array $paths, $extension = null) |
||
| 227 | |||
| 228 | /** |
||
| 229 | * {@inheritdoc} |
||
| 230 | */ |
||
| 231 | protected function getYamlMappingDriver(array $paths, $extension = null) |
||
| 237 | |||
| 238 | /** |
||
| 239 | * {@inheritdoc} |
||
| 240 | * |
||
| 241 | * @throws \InvalidArgumentException |
||
| 242 | * |
||
| 243 | * @return RepositoryFactory|null |
||
| 244 | */ |
||
| 245 | protected function getRepositoryFactory() |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Retrieve query cache driver. |
||
| 265 | * |
||
| 266 | * @throws \InvalidArgumentException |
||
| 267 | * |
||
| 268 | * @return CacheProvider |
||
| 269 | */ |
||
| 270 | public function getQueryCacheDriver() |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Set query cache driver. |
||
| 284 | * |
||
| 285 | * @param CacheProvider $queryCacheDriver |
||
| 286 | */ |
||
| 287 | public function setQueryCacheDriver(CacheProvider $queryCacheDriver) |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Retrieve result cache driver. |
||
| 294 | * |
||
| 295 | * @throws \InvalidArgumentException |
||
| 296 | * |
||
| 297 | * @return CacheProvider |
||
| 298 | */ |
||
| 299 | public function getResultCacheDriver() |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Set result cache driver. |
||
| 313 | * |
||
| 314 | * @param CacheProvider $resultCacheDriver |
||
| 315 | */ |
||
| 316 | public function setResultCacheDriver(CacheProvider $resultCacheDriver) |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Retrieve hydrator cache driver. |
||
| 323 | * |
||
| 324 | * @throws \InvalidArgumentException |
||
| 325 | * |
||
| 326 | * @return CacheProvider |
||
| 327 | */ |
||
| 328 | public function getHydratorCacheDriver() |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Set hydrator cache driver. |
||
| 342 | * |
||
| 343 | * @param CacheProvider $hydratorCacheDriver |
||
| 344 | */ |
||
| 345 | public function setHydratorCacheDriver(CacheProvider $hydratorCacheDriver) |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Get cache driver. |
||
| 352 | * |
||
| 353 | * @param string $cacheNamespace |
||
| 354 | * @param CacheProvider $cacheDriver |
||
|
|
|||
| 355 | * |
||
| 356 | * @return CacheProvider |
||
| 357 | */ |
||
| 358 | protected function getCacheDriver($cacheNamespace, CacheProvider $cacheDriver = null) |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Retrieve naming strategy. |
||
| 374 | * |
||
| 375 | * @return NamingStrategy |
||
| 376 | */ |
||
| 377 | protected function getNamingStrategy() |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Retrieve quote strategy. |
||
| 394 | * |
||
| 395 | * @throws \InvalidArgumentException |
||
| 396 | * |
||
| 397 | * @return QuoteStrategy |
||
| 398 | */ |
||
| 399 | protected function getQuoteStrategy() |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Retrieve SQL logger. |
||
| 416 | * |
||
| 417 | * @return SQLLogger|null |
||
| 418 | */ |
||
| 419 | protected function getSQLLogger() |
||
| 431 | |||
| 432 | /** |
||
| 433 | * Retrieve custom DQL string functions. |
||
| 434 | * |
||
| 435 | * @return array |
||
| 436 | */ |
||
| 437 | protected function getCustomStringFunctions() |
||
| 449 | |||
| 450 | /** |
||
| 451 | * Retrieve custom DQL numeric functions. |
||
| 452 | * |
||
| 453 | * @return array |
||
| 454 | */ |
||
| 455 | protected function getCustomNumericFunctions() |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Retrieve custom DQL date time functions. |
||
| 470 | * |
||
| 471 | * @return array |
||
| 472 | */ |
||
| 473 | protected function getCustomDateTimeFunctions() |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Retrieve custom DBAL types. |
||
| 488 | * |
||
| 489 | * @return array |
||
| 490 | */ |
||
| 491 | protected function getCustomTypes() |
||
| 503 | |||
| 504 | /** |
||
| 505 | * Get custom registered filters. |
||
| 506 | * |
||
| 507 | * @return array |
||
| 508 | */ |
||
| 509 | protected function getCustomFilters() |
||
| 521 | |||
| 522 | /** |
||
| 523 | * {@inheritdoc} |
||
| 524 | * |
||
| 525 | * @throws \Doctrine\DBAL\DBALException |
||
| 526 | * @throws \Doctrine\ORM\ORMException |
||
| 527 | * @throws \InvalidArgumentException |
||
| 528 | * @throws \RuntimeException |
||
| 529 | * @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
||
| 530 | * @throws \Symfony\Component\Console\Exception\LogicException |
||
| 531 | * @throws \UnexpectedValueException |
||
| 532 | * |
||
| 533 | * @return Command[] |
||
| 534 | */ |
||
| 535 | public function getConsoleCommands() |
||
| 587 | |||
| 588 | /** |
||
| 589 | * {@inheritdoc} |
||
| 590 | * |
||
| 591 | * @throws \Doctrine\DBAL\DBALException |
||
| 592 | * @throws \Doctrine\ORM\ORMException |
||
| 593 | * @throws \InvalidArgumentException |
||
| 594 | * @throws \RuntimeException |
||
| 595 | * @throws \UnexpectedValueException |
||
| 596 | */ |
||
| 597 | public function getConsoleHelperSet() |
||
| 607 | } |
||
| 608 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.