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 |
||
| 38 | class RelationalBuilder extends AbstractManagerBuilder |
||
| 39 | { |
||
| 40 | /** |
||
| 41 | * Entity Manager. |
||
| 42 | * |
||
| 43 | * @var EntityManager |
||
| 44 | */ |
||
| 45 | protected $manager; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Query cache driver. |
||
| 49 | * |
||
| 50 | * @var CacheProvider |
||
| 51 | */ |
||
| 52 | protected $queryCacheDriver; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Result cache driver. |
||
| 56 | * |
||
| 57 | * @var CacheProvider |
||
| 58 | */ |
||
| 59 | protected $resultCacheDriver; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Naming strategy. |
||
| 63 | * |
||
| 64 | * @var NamingStrategy |
||
| 65 | */ |
||
| 66 | protected $namingStrategy; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Quote strategy. |
||
| 70 | * |
||
| 71 | * @var QuoteStrategy |
||
| 72 | */ |
||
| 73 | protected $quoteStrategy; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * SQL logger. |
||
| 77 | * |
||
| 78 | * @var SQLLogger |
||
| 79 | */ |
||
| 80 | protected $SQLLogger; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * {@inheritdoc} |
||
| 84 | */ |
||
| 85 | protected function getDefaultOptions() |
||
| 96 | |||
| 97 | /** |
||
| 98 | * {@inheritdoc} |
||
| 99 | * |
||
| 100 | * @throws \Doctrine\DBAL\DBALException |
||
| 101 | * @throws \Doctrine\ORM\ORMException |
||
| 102 | * @throws \InvalidArgumentException |
||
| 103 | * @throws \RuntimeException |
||
| 104 | * @throws \UnexpectedValueException |
||
| 105 | * |
||
| 106 | * @return EntityManager |
||
| 107 | */ |
||
| 108 | public function getManager($force = false) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * {@inheritdoc} |
||
| 123 | */ |
||
| 124 | protected function wipe() |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Build new Doctrine entity manager. |
||
| 138 | * |
||
| 139 | * @throws \Doctrine\DBAL\DBALException |
||
| 140 | * @throws \Doctrine\ORM\ORMException |
||
| 141 | * @throws \InvalidArgumentException |
||
| 142 | * @throws \RuntimeException |
||
| 143 | * @throws \UnexpectedValueException |
||
| 144 | * |
||
| 145 | * @return EntityManager |
||
| 146 | */ |
||
| 147 | protected function buildManager() |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Set up general manager configurations. |
||
| 177 | * |
||
| 178 | * @param Configuration $config |
||
| 179 | */ |
||
| 180 | protected function setUpGeneralConfigurations(Configuration $config) |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Set up manager specific configurations. |
||
| 202 | * |
||
| 203 | * @param Configuration $config |
||
| 204 | */ |
||
| 205 | protected function setUpSpecificConfigurations(Configuration $config) |
||
| 224 | |||
| 225 | /** |
||
| 226 | * {@inheritdoc} |
||
| 227 | */ |
||
| 228 | protected function getAnnotationMetadataDriver(array $paths) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * {@inheritdoc} |
||
| 235 | */ |
||
| 236 | protected function getXmlMetadataDriver(array $paths, $extension = null) |
||
| 242 | |||
| 243 | /** |
||
| 244 | * {@inheritdoc} |
||
| 245 | */ |
||
| 246 | protected function getYamlMetadataDriver(array $paths, $extension = null) |
||
| 252 | |||
| 253 | /** |
||
| 254 | * {@inheritdoc} |
||
| 255 | * |
||
| 256 | * @throws \InvalidArgumentException |
||
| 257 | * |
||
| 258 | * @return RepositoryFactory|null |
||
| 259 | */ |
||
| 260 | protected function getRepositoryFactory() |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Retrieve query cache driver. |
||
| 280 | * |
||
| 281 | * @throws \InvalidArgumentException |
||
| 282 | * |
||
| 283 | * @return CacheProvider |
||
| 284 | */ |
||
| 285 | public function getQueryCacheDriver() |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Set query cache driver. |
||
| 308 | * |
||
| 309 | * @param CacheProvider $queryCacheDriver |
||
| 310 | */ |
||
| 311 | public function setQueryCacheDriver(CacheProvider $queryCacheDriver) |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Retrieve result cache driver. |
||
| 318 | * |
||
| 319 | * @throws \InvalidArgumentException |
||
| 320 | * |
||
| 321 | * @return CacheProvider |
||
| 322 | */ |
||
| 323 | public function getResultCacheDriver() |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Set result cache driver. |
||
| 346 | * |
||
| 347 | * @param CacheProvider $resultCacheDriver |
||
| 348 | */ |
||
| 349 | public function setResultCacheDriver(CacheProvider $resultCacheDriver) |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Retrieve naming strategy. |
||
| 356 | * |
||
| 357 | * @return NamingStrategy |
||
| 358 | */ |
||
| 359 | protected function getNamingStrategy() |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Retrieve quote strategy. |
||
| 376 | * |
||
| 377 | * @throws \InvalidArgumentException |
||
| 378 | * |
||
| 379 | * @return QuoteStrategy |
||
| 380 | */ |
||
| 381 | protected function getQuoteStrategy() |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Retrieve SQL logger. |
||
| 398 | * |
||
| 399 | * @return SQLLogger|null |
||
| 400 | */ |
||
| 401 | protected function getSQLLogger() |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Retrieve custom DQL string functions. |
||
| 416 | * |
||
| 417 | * @return array |
||
| 418 | */ |
||
| 419 | protected function getCustomStringFunctions() |
||
| 431 | |||
| 432 | /** |
||
| 433 | * Retrieve custom DQL numeric functions. |
||
| 434 | * |
||
| 435 | * @return array |
||
| 436 | */ |
||
| 437 | protected function getCustomNumericFunctions() |
||
| 449 | |||
| 450 | /** |
||
| 451 | * Retrieve custom DQL date time functions. |
||
| 452 | * |
||
| 453 | * @return array |
||
| 454 | */ |
||
| 455 | protected function getCustomDateTimeFunctions() |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Retrieve custom DBAL types. |
||
| 470 | * |
||
| 471 | * @return array |
||
| 472 | */ |
||
| 473 | protected function getCustomTypes() |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Get custom registered filters. |
||
| 488 | * |
||
| 489 | * @return array |
||
| 490 | */ |
||
| 491 | protected function getCustomFilters() |
||
| 503 | |||
| 504 | /** |
||
| 505 | * {@inheritdoc} |
||
| 506 | * |
||
| 507 | * @throws \Doctrine\DBAL\DBALException |
||
| 508 | * @throws \Doctrine\ORM\ORMException |
||
| 509 | * @throws \InvalidArgumentException |
||
| 510 | * @throws \RuntimeException |
||
| 511 | * @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
||
| 512 | * @throws \Symfony\Component\Console\Exception\LogicException |
||
| 513 | * @throws \UnexpectedValueException |
||
| 514 | * |
||
| 515 | * @return Command[] |
||
| 516 | */ |
||
| 517 | public function getConsoleCommands() |
||
| 569 | |||
| 570 | /** |
||
| 571 | * {@inheritdoc} |
||
| 572 | * |
||
| 573 | * @throws \Doctrine\DBAL\DBALException |
||
| 574 | * @throws \Doctrine\ORM\ORMException |
||
| 575 | * @throws \InvalidArgumentException |
||
| 576 | * @throws \RuntimeException |
||
| 577 | * @throws \UnexpectedValueException |
||
| 578 | */ |
||
| 579 | public function getConsoleHelperSet() |
||
| 588 | } |
||
| 589 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: