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 |
||
| 37 | class RelationalBuilder extends AbstractManagerBuilder |
||
| 38 | { |
||
| 39 | /** |
||
| 40 | * Entity Manager. |
||
| 41 | * |
||
| 42 | * @var EntityManager |
||
| 43 | */ |
||
| 44 | protected $manager; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Query cache driver. |
||
| 48 | * |
||
| 49 | * @var CacheProvider |
||
| 50 | */ |
||
| 51 | protected $queryCacheDriver; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Result cache driver. |
||
| 55 | * |
||
| 56 | * @var CacheProvider |
||
| 57 | */ |
||
| 58 | protected $resultCacheDriver; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Naming strategy. |
||
| 62 | * |
||
| 63 | * @var NamingStrategy |
||
| 64 | */ |
||
| 65 | protected $namingStrategy; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Quote strategy. |
||
| 69 | * |
||
| 70 | * @var QuoteStrategy |
||
| 71 | */ |
||
| 72 | protected $quoteStrategy; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * SQL logger. |
||
| 76 | * |
||
| 77 | * @var SQLLogger |
||
| 78 | */ |
||
| 79 | protected $SQLLogger; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * {@inheritdoc} |
||
| 83 | */ |
||
| 84 | protected function getDefaultOptions() |
||
| 95 | |||
| 96 | /** |
||
| 97 | * {@inheritdoc} |
||
| 98 | * |
||
| 99 | * @throws \Doctrine\DBAL\DBALException |
||
| 100 | * @throws \Doctrine\ORM\ORMException |
||
| 101 | * @throws \InvalidArgumentException |
||
| 102 | * @throws \RuntimeException |
||
| 103 | * @throws \UnexpectedValueException |
||
| 104 | * |
||
| 105 | * @return EntityManager |
||
| 106 | */ |
||
| 107 | public function getManager($force = false) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * {@inheritdoc} |
||
| 122 | */ |
||
| 123 | protected function wipe() |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Build new Doctrine entity manager. |
||
| 137 | * |
||
| 138 | * @throws \Doctrine\DBAL\DBALException |
||
| 139 | * @throws \Doctrine\ORM\ORMException |
||
| 140 | * @throws \InvalidArgumentException |
||
| 141 | * @throws \RuntimeException |
||
| 142 | * @throws \UnexpectedValueException |
||
| 143 | * |
||
| 144 | * @return EntityManager |
||
| 145 | */ |
||
| 146 | protected function buildManager() |
||
| 187 | |||
| 188 | /** |
||
| 189 | * {@inheritdoc} |
||
| 190 | */ |
||
| 191 | protected function getAnnotationMetadataDriver(array $paths) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * {@inheritdoc} |
||
| 198 | */ |
||
| 199 | protected function getXmlMetadataDriver(array $paths, $extension = null) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * {@inheritdoc} |
||
| 206 | */ |
||
| 207 | protected function getYamlMetadataDriver(array $paths, $extension = null) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * {@inheritdoc} |
||
| 214 | * |
||
| 215 | * @throws \InvalidArgumentException |
||
| 216 | * |
||
| 217 | * @return RepositoryFactory|null |
||
| 218 | */ |
||
| 219 | protected function getRepositoryFactory() |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Retrieve query cache driver. |
||
| 239 | * |
||
| 240 | * @throws \InvalidArgumentException |
||
| 241 | * |
||
| 242 | * @return CacheProvider |
||
| 243 | */ |
||
| 244 | public function getQueryCacheDriver() |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Set query cache driver. |
||
| 267 | * |
||
| 268 | * @param CacheProvider $queryCacheDriver |
||
| 269 | */ |
||
| 270 | public function setQueryCacheDriver(CacheProvider $queryCacheDriver) |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Retrieve result cache driver. |
||
| 277 | * |
||
| 278 | * @throws \InvalidArgumentException |
||
| 279 | * |
||
| 280 | * @return CacheProvider |
||
| 281 | */ |
||
| 282 | public function getResultCacheDriver() |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Set result cache driver. |
||
| 305 | * |
||
| 306 | * @param CacheProvider $resultCacheDriver |
||
| 307 | */ |
||
| 308 | public function setResultCacheDriver(CacheProvider $resultCacheDriver) |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Retrieve naming strategy. |
||
| 315 | * |
||
| 316 | * @return NamingStrategy |
||
| 317 | */ |
||
| 318 | protected function getNamingStrategy() |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Retrieve quote strategy. |
||
| 335 | * |
||
| 336 | * @throws \InvalidArgumentException |
||
| 337 | * |
||
| 338 | * @return QuoteStrategy |
||
| 339 | */ |
||
| 340 | protected function getQuoteStrategy() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Retrieve SQL logger. |
||
| 357 | * |
||
| 358 | * @return SQLLogger|null |
||
| 359 | */ |
||
| 360 | protected function getSQLLogger() |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Retrieve custom DQL string functions. |
||
| 375 | * |
||
| 376 | * @return array |
||
| 377 | */ |
||
| 378 | protected function getCustomStringFunctions() |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Retrieve custom DQL numeric functions. |
||
| 393 | * |
||
| 394 | * @return array |
||
| 395 | */ |
||
| 396 | protected function getCustomNumericFunctions() |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Retrieve custom DQL date time functions. |
||
| 411 | * |
||
| 412 | * @return array |
||
| 413 | */ |
||
| 414 | protected function getCustomDateTimeFunctions() |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Retrieve custom DBAL types. |
||
| 429 | * |
||
| 430 | * @return array |
||
| 431 | */ |
||
| 432 | protected function getCustomTypes() |
||
| 444 | |||
| 445 | /** |
||
| 446 | * {@inheritdoc} |
||
| 447 | * |
||
| 448 | * @throws \Doctrine\DBAL\DBALException |
||
| 449 | * @throws \Doctrine\ORM\ORMException |
||
| 450 | * @throws \InvalidArgumentException |
||
| 451 | * @throws \RuntimeException |
||
| 452 | * @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
||
| 453 | * @throws \Symfony\Component\Console\Exception\LogicException |
||
| 454 | * @throws \UnexpectedValueException |
||
| 455 | * |
||
| 456 | * @return Command[] |
||
| 457 | */ |
||
| 458 | public function getConsoleCommands() |
||
| 506 | |||
| 507 | /** |
||
| 508 | * {@inheritdoc} |
||
| 509 | * |
||
| 510 | * @throws \Doctrine\DBAL\DBALException |
||
| 511 | * @throws \Doctrine\ORM\ORMException |
||
| 512 | * @throws \InvalidArgumentException |
||
| 513 | * @throws \RuntimeException |
||
| 514 | * @throws \UnexpectedValueException |
||
| 515 | */ |
||
| 516 | public function getConsoleHelperSet() |
||
| 525 | } |
||
| 526 |
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: