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() |
||
| 188 | |||
| 189 | /** |
||
| 190 | * {@inheritdoc} |
||
| 191 | */ |
||
| 192 | protected function getAnnotationMetadataDriver(array $paths) |
||
| 196 | |||
| 197 | /** |
||
| 198 | * {@inheritdoc} |
||
| 199 | */ |
||
| 200 | protected function getXmlMetadataDriver(array $paths, $extension = null) |
||
| 204 | |||
| 205 | /** |
||
| 206 | * {@inheritdoc} |
||
| 207 | */ |
||
| 208 | protected function getYamlMetadataDriver(array $paths, $extension = null) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * {@inheritdoc} |
||
| 215 | * |
||
| 216 | * @throws \InvalidArgumentException |
||
| 217 | * |
||
| 218 | * @return RepositoryFactory|null |
||
| 219 | */ |
||
| 220 | protected function getRepositoryFactory() |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Retrieve query cache driver. |
||
| 240 | * |
||
| 241 | * @throws \InvalidArgumentException |
||
| 242 | * |
||
| 243 | * @return CacheProvider |
||
| 244 | */ |
||
| 245 | public function getQueryCacheDriver() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Set query cache driver. |
||
| 268 | * |
||
| 269 | * @param CacheProvider $queryCacheDriver |
||
| 270 | */ |
||
| 271 | public function setQueryCacheDriver(CacheProvider $queryCacheDriver) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Retrieve result cache driver. |
||
| 278 | * |
||
| 279 | * @throws \InvalidArgumentException |
||
| 280 | * |
||
| 281 | * @return CacheProvider |
||
| 282 | */ |
||
| 283 | public function getResultCacheDriver() |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Set result cache driver. |
||
| 306 | * |
||
| 307 | * @param CacheProvider $resultCacheDriver |
||
| 308 | */ |
||
| 309 | public function setResultCacheDriver(CacheProvider $resultCacheDriver) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Retrieve naming strategy. |
||
| 316 | * |
||
| 317 | * @return NamingStrategy |
||
| 318 | */ |
||
| 319 | protected function getNamingStrategy() |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Retrieve quote strategy. |
||
| 336 | * |
||
| 337 | * @throws \InvalidArgumentException |
||
| 338 | * |
||
| 339 | * @return QuoteStrategy |
||
| 340 | */ |
||
| 341 | protected function getQuoteStrategy() |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Retrieve SQL logger. |
||
| 358 | * |
||
| 359 | * @return SQLLogger|null |
||
| 360 | */ |
||
| 361 | protected function getSQLLogger() |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Retrieve custom DQL string functions. |
||
| 376 | * |
||
| 377 | * @return array |
||
| 378 | */ |
||
| 379 | protected function getCustomStringFunctions() |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Retrieve custom DQL numeric functions. |
||
| 394 | * |
||
| 395 | * @return array |
||
| 396 | */ |
||
| 397 | protected function getCustomNumericFunctions() |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Retrieve custom DQL date time functions. |
||
| 412 | * |
||
| 413 | * @return array |
||
| 414 | */ |
||
| 415 | protected function getCustomDateTimeFunctions() |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Retrieve custom DBAL types. |
||
| 430 | * |
||
| 431 | * @return array |
||
| 432 | */ |
||
| 433 | protected function getCustomTypes() |
||
| 445 | |||
| 446 | /** |
||
| 447 | * {@inheritdoc} |
||
| 448 | * |
||
| 449 | * @throws \Doctrine\DBAL\DBALException |
||
| 450 | * @throws \Doctrine\ORM\ORMException |
||
| 451 | * @throws \InvalidArgumentException |
||
| 452 | * @throws \RuntimeException |
||
| 453 | * @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
||
| 454 | * @throws \Symfony\Component\Console\Exception\LogicException |
||
| 455 | * @throws \UnexpectedValueException |
||
| 456 | * |
||
| 457 | * @return Command[] |
||
| 458 | */ |
||
| 459 | public function getConsoleCommands() |
||
| 511 | |||
| 512 | /** |
||
| 513 | * {@inheritdoc} |
||
| 514 | * |
||
| 515 | * @throws \Doctrine\DBAL\DBALException |
||
| 516 | * @throws \Doctrine\ORM\ORMException |
||
| 517 | * @throws \InvalidArgumentException |
||
| 518 | * @throws \RuntimeException |
||
| 519 | * @throws \UnexpectedValueException |
||
| 520 | */ |
||
| 521 | public function getConsoleHelperSet() |
||
| 530 | } |
||
| 531 |
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: