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) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * {@inheritdoc} |
||
| 225 | */ |
||
| 226 | protected function getAnnotationMappingDriver(array $paths) |
||
| 230 | |||
| 231 | /** |
||
| 232 | * {@inheritdoc} |
||
| 233 | */ |
||
| 234 | protected function getXmlMappingDriver(array $paths, $extension = null) |
||
| 240 | |||
| 241 | /** |
||
| 242 | * {@inheritdoc} |
||
| 243 | */ |
||
| 244 | protected function getYamlMappingDriver(array $paths, $extension = null) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * {@inheritdoc} |
||
| 253 | * |
||
| 254 | * @throws \InvalidArgumentException |
||
| 255 | * |
||
| 256 | * @return RepositoryFactory|null |
||
| 257 | */ |
||
| 258 | protected function getRepositoryFactory() |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Retrieve query cache driver. |
||
| 278 | * |
||
| 279 | * @throws \InvalidArgumentException |
||
| 280 | * |
||
| 281 | * @return CacheProvider |
||
| 282 | */ |
||
| 283 | public function getQueryCacheDriver() |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Set query cache driver. |
||
| 306 | * |
||
| 307 | * @param CacheProvider $queryCacheDriver |
||
| 308 | */ |
||
| 309 | public function setQueryCacheDriver(CacheProvider $queryCacheDriver) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Retrieve result cache driver. |
||
| 316 | * |
||
| 317 | * @throws \InvalidArgumentException |
||
| 318 | * |
||
| 319 | * @return CacheProvider |
||
| 320 | */ |
||
| 321 | public function getResultCacheDriver() |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Set result cache driver. |
||
| 344 | * |
||
| 345 | * @param CacheProvider $resultCacheDriver |
||
| 346 | */ |
||
| 347 | public function setResultCacheDriver(CacheProvider $resultCacheDriver) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Retrieve naming strategy. |
||
| 354 | * |
||
| 355 | * @return NamingStrategy |
||
| 356 | */ |
||
| 357 | protected function getNamingStrategy() |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Retrieve quote strategy. |
||
| 374 | * |
||
| 375 | * @throws \InvalidArgumentException |
||
| 376 | * |
||
| 377 | * @return QuoteStrategy |
||
| 378 | */ |
||
| 379 | protected function getQuoteStrategy() |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Retrieve SQL logger. |
||
| 396 | * |
||
| 397 | * @return SQLLogger|null |
||
| 398 | */ |
||
| 399 | protected function getSQLLogger() |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Retrieve custom DQL string functions. |
||
| 414 | * |
||
| 415 | * @return array |
||
| 416 | */ |
||
| 417 | protected function getCustomStringFunctions() |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Retrieve custom DQL numeric functions. |
||
| 432 | * |
||
| 433 | * @return array |
||
| 434 | */ |
||
| 435 | protected function getCustomNumericFunctions() |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Retrieve custom DQL date time functions. |
||
| 450 | * |
||
| 451 | * @return array |
||
| 452 | */ |
||
| 453 | protected function getCustomDateTimeFunctions() |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Retrieve custom DBAL types. |
||
| 468 | * |
||
| 469 | * @return array |
||
| 470 | */ |
||
| 471 | protected function getCustomTypes() |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Get custom registered filters. |
||
| 486 | * |
||
| 487 | * @return array |
||
| 488 | */ |
||
| 489 | protected function getCustomFilters() |
||
| 501 | |||
| 502 | /** |
||
| 503 | * {@inheritdoc} |
||
| 504 | * |
||
| 505 | * @throws \Doctrine\DBAL\DBALException |
||
| 506 | * @throws \Doctrine\ORM\ORMException |
||
| 507 | * @throws \InvalidArgumentException |
||
| 508 | * @throws \RuntimeException |
||
| 509 | * @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
||
| 510 | * @throws \Symfony\Component\Console\Exception\LogicException |
||
| 511 | * @throws \UnexpectedValueException |
||
| 512 | * |
||
| 513 | * @return Command[] |
||
| 514 | */ |
||
| 515 | public function getConsoleCommands() |
||
| 567 | |||
| 568 | /** |
||
| 569 | * {@inheritdoc} |
||
| 570 | * |
||
| 571 | * @throws \Doctrine\DBAL\DBALException |
||
| 572 | * @throws \Doctrine\ORM\ORMException |
||
| 573 | * @throws \InvalidArgumentException |
||
| 574 | * @throws \RuntimeException |
||
| 575 | * @throws \UnexpectedValueException |
||
| 576 | */ |
||
| 577 | public function getConsoleHelperSet() |
||
| 586 | } |
||
| 587 |
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: