Complex classes like Configuration 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 Configuration, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class Configuration extends DBALConfiguration |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Set the cache key for the metadata cache. Cache key |
||
| 23 | * is assembled as "doctrine.cache.{key}" and pulled from |
||
| 24 | * service locator. |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $metadataCache = 'array'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Set the cache key for the query cache. Cache key |
||
| 32 | * is assembled as "doctrine.cache.{key}" and pulled from |
||
| 33 | * service locator. |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $queryCache = 'array'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Set the cache key for the result cache. Cache key |
||
| 41 | * is assembled as "doctrine.cache.{key}" and pulled from |
||
| 42 | * service locator. |
||
| 43 | * |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | protected $resultCache = 'array'; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Set the cache key for the hydration cache. Cache key |
||
| 50 | * is assembled as "doctrine.cache.{key}" and pulled from |
||
| 51 | * service locator. |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | protected $hydrationCache = 'array'; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Set the driver key for the metadata driver. Driver key |
||
| 59 | * is assembled as "doctrine.driver.{key}" and pulled from |
||
| 60 | * service locator. |
||
| 61 | * |
||
| 62 | * @var string |
||
| 63 | */ |
||
| 64 | protected $driver = 'orm_default'; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Automatic generation of proxies (disable for production!) |
||
| 68 | * |
||
| 69 | * @var bool |
||
| 70 | */ |
||
| 71 | protected $generateProxies = true; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Proxy directory. |
||
| 75 | * |
||
| 76 | * @var string |
||
| 77 | */ |
||
| 78 | protected $proxyDir = 'data'; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Proxy namespace. |
||
| 82 | * |
||
| 83 | * @var string |
||
| 84 | */ |
||
| 85 | protected $proxyNamespace = 'DoctrineORMModule\Proxy'; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Entity alias map. |
||
| 89 | * |
||
| 90 | * @var array |
||
| 91 | */ |
||
| 92 | protected $entityNamespaces = []; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Keys must be function names and values the FQCN of the implementing class. |
||
| 96 | * The function names will be case-insensitive in DQL. |
||
| 97 | * |
||
| 98 | * @var array |
||
| 99 | */ |
||
| 100 | protected $datetimeFunctions = []; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Keys must be function names and values the FQCN of the implementing class. |
||
| 104 | * The function names will be case-insensitive in DQL. |
||
| 105 | * |
||
| 106 | * @var array |
||
| 107 | */ |
||
| 108 | protected $stringFunctions = []; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Keys must be function names and values the FQCN of the implementing class. |
||
| 112 | * The function names will be case-insensitive in DQL. |
||
| 113 | * |
||
| 114 | * @var array |
||
| 115 | */ |
||
| 116 | protected $numericFunctions = []; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Keys must be the name of the custom filter and the value must be |
||
| 120 | * the class name for the custom filter. |
||
| 121 | * |
||
| 122 | * @var array |
||
| 123 | */ |
||
| 124 | protected $filters = []; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Keys must be the name of the query and values the DQL query string. |
||
| 128 | * |
||
| 129 | * @var array |
||
| 130 | */ |
||
| 131 | protected $namedQueries = []; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Keys must be the name of the query and the value is an array containing |
||
| 135 | * the keys 'sql' for native SQL query string and 'rsm' for the Query\ResultSetMapping. |
||
| 136 | * |
||
| 137 | * @var array |
||
| 138 | */ |
||
| 139 | protected $namedNativeQueries = []; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Keys must be the name of the custom hydration method and the value must be |
||
| 143 | * the class name for the custom hydrator |
||
| 144 | * |
||
| 145 | * @var array |
||
| 146 | */ |
||
| 147 | protected $customHydrationModes = []; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Naming strategy or name of the naming strategy service to be set in ORM |
||
| 151 | * configuration (if any) |
||
| 152 | * |
||
| 153 | * @var string|null|NamingStrategy |
||
| 154 | */ |
||
| 155 | protected $namingStrategy; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Quote strategy or name of the quote strategy service to be set in ORM |
||
| 159 | * configuration (if any) |
||
| 160 | * |
||
| 161 | * @var string|null|QuoteStrategy |
||
| 162 | */ |
||
| 163 | protected $quoteStrategy; |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Default repository class |
||
| 167 | * |
||
| 168 | * @var string|null |
||
| 169 | */ |
||
| 170 | protected $defaultRepositoryClassName; |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Repository factory or name of the repository factory service to be set in ORM |
||
| 174 | * configuration (if any) |
||
| 175 | * |
||
| 176 | * @var string|null|RepositoryFactory |
||
| 177 | */ |
||
| 178 | protected $repositoryFactory; |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Class name of MetaData factory to be set in ORM. |
||
| 182 | * The entityManager will create a new instance on construction. |
||
| 183 | * |
||
| 184 | * @var string |
||
| 185 | */ |
||
| 186 | protected $classMetadataFactoryName; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Entity listener resolver or service name of the entity listener resolver |
||
| 190 | * to be set in ORM configuration (if any) |
||
| 191 | * |
||
| 192 | * @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html |
||
| 193 | * @var string|null|EntityListenerResolver |
||
| 194 | */ |
||
| 195 | protected $entityListenerResolver; |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Configuration for second level cache |
||
| 199 | * |
||
| 200 | * @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/second-level-cache.html |
||
| 201 | * @var SecondLevelCacheConfiguration|null |
||
| 202 | */ |
||
| 203 | protected $secondLevelCache; |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Configuration for schema filter |
||
| 207 | * |
||
| 208 | * @var string|null |
||
| 209 | 72 | */ |
|
| 210 | protected $schemaFilter; |
||
| 211 | 72 | ||
| 212 | /** |
||
| 213 | 72 | * @param array $datetimeFunctions |
|
| 214 | * @return self |
||
| 215 | */ |
||
| 216 | public function setDatetimeFunctions($datetimeFunctions) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @return array |
||
| 225 | */ |
||
| 226 | public function getDatetimeFunctions() |
||
| 230 | 72 | ||
| 231 | /** |
||
| 232 | 72 | * @param string $driver |
|
| 233 | * @return self |
||
| 234 | */ |
||
| 235 | public function setDriver($driver) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @return string |
||
| 244 | */ |
||
| 245 | public function getDriver() |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @param array $entityNamespaces |
||
| 252 | * @return self |
||
| 253 | */ |
||
| 254 | public function setEntityNamespaces($entityNamespaces) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @return array |
||
| 263 | */ |
||
| 264 | public function getEntityNamespaces() |
||
| 268 | 72 | ||
| 269 | /** |
||
| 270 | 72 | * @param boolean $generateProxies |
|
| 271 | * @return self |
||
| 272 | */ |
||
| 273 | public function setGenerateProxies($generateProxies) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @return boolean |
||
| 282 | */ |
||
| 283 | public function getGenerateProxies() |
||
| 287 | 72 | ||
| 288 | /** |
||
| 289 | 72 | * @param string $metadataCache |
|
| 290 | * @return self |
||
| 291 | */ |
||
| 292 | public function setMetadataCache($metadataCache) |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @return string |
||
| 301 | */ |
||
| 302 | public function getMetadataCache() |
||
| 306 | 73 | ||
| 307 | /** |
||
| 308 | 73 | * @param string $resultCache |
|
| 309 | * @return self |
||
| 310 | */ |
||
| 311 | public function setResultCache($resultCache) |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @return string |
||
| 320 | */ |
||
| 321 | public function getResultCache() |
||
| 325 | 74 | ||
| 326 | /** |
||
| 327 | 74 | * @param string $hydrationCache |
|
| 328 | * @return self |
||
| 329 | */ |
||
| 330 | public function setHydrationCache($hydrationCache) |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @return string |
||
| 339 | */ |
||
| 340 | public function getHydrationCache() |
||
| 344 | |||
| 345 | /** |
||
| 346 | * @param array $namedNativeQueries |
||
| 347 | * @return self |
||
| 348 | */ |
||
| 349 | public function setNamedNativeQueries($namedNativeQueries) |
||
| 355 | |||
| 356 | /** |
||
| 357 | * @return array |
||
| 358 | */ |
||
| 359 | public function getNamedNativeQueries() |
||
| 363 | |||
| 364 | /** |
||
| 365 | * @param array $namedQueries |
||
| 366 | * @return self |
||
| 367 | */ |
||
| 368 | public function setNamedQueries($namedQueries) |
||
| 374 | |||
| 375 | /** |
||
| 376 | * @return array |
||
| 377 | */ |
||
| 378 | public function getNamedQueries() |
||
| 382 | 72 | ||
| 383 | /** |
||
| 384 | 72 | * @param array $numericFunctions |
|
| 385 | * @return self |
||
| 386 | */ |
||
| 387 | public function setNumericFunctions($numericFunctions) |
||
| 393 | |||
| 394 | /** |
||
| 395 | * @return array |
||
| 396 | */ |
||
| 397 | public function getNumericFunctions() |
||
| 401 | |||
| 402 | 72 | /** |
|
| 403 | * |
||
| 404 | 72 | * @param array $filters |
|
| 405 | * @return self |
||
| 406 | */ |
||
| 407 | public function setFilters($filters) |
||
| 413 | 88 | ||
| 414 | /** |
||
| 415 | * |
||
| 416 | * @return array |
||
| 417 | */ |
||
| 418 | public function getFilters() |
||
| 422 | 72 | ||
| 423 | /** |
||
| 424 | 72 | * @param string $proxyDir |
|
| 425 | * @return self |
||
| 426 | */ |
||
| 427 | public function setProxyDir($proxyDir) |
||
| 433 | |||
| 434 | /** |
||
| 435 | * @return string |
||
| 436 | */ |
||
| 437 | public function getProxyDir() |
||
| 441 | 72 | ||
| 442 | /** |
||
| 443 | 72 | * @param string $proxyNamespace |
|
| 444 | * @return self |
||
| 445 | */ |
||
| 446 | public function setProxyNamespace($proxyNamespace) |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @return string |
||
| 455 | */ |
||
| 456 | public function getProxyNamespace() |
||
| 460 | 72 | ||
| 461 | /** |
||
| 462 | 72 | * @param string $queryCache |
|
| 463 | * @return self |
||
| 464 | */ |
||
| 465 | public function setQueryCache($queryCache) |
||
| 471 | |||
| 472 | /** |
||
| 473 | * @return string |
||
| 474 | */ |
||
| 475 | public function getQueryCache() |
||
| 479 | 72 | ||
| 480 | /** |
||
| 481 | 72 | * @param array $stringFunctions |
|
| 482 | * @return self |
||
| 483 | */ |
||
| 484 | public function setStringFunctions($stringFunctions) |
||
| 490 | |||
| 491 | /** |
||
| 492 | * @return array |
||
| 493 | */ |
||
| 494 | public function getStringFunctions() |
||
| 498 | |||
| 499 | /** |
||
| 500 | * @param array $modes |
||
| 501 | * @return self |
||
| 502 | */ |
||
| 503 | public function setCustomHydrationModes($modes) |
||
| 509 | |||
| 510 | /** |
||
| 511 | * @return array |
||
| 512 | */ |
||
| 513 | public function getCustomHydrationModes() |
||
| 517 | |||
| 518 | 4 | /** |
|
| 519 | 4 | * @param string|null|NamingStrategy $namingStrategy |
|
| 520 | 4 | * @return self |
|
| 521 | 4 | * @throws InvalidArgumentException when the provided naming strategy does not fit the expected type |
|
| 522 | 4 | */ |
|
| 523 | public function setNamingStrategy($namingStrategy) |
||
| 542 | |||
| 543 | /** |
||
| 544 | * @return string|null|NamingStrategy |
||
| 545 | */ |
||
| 546 | public function getNamingStrategy() |
||
| 550 | |||
| 551 | 4 | /** |
|
| 552 | 4 | * @param string|null|QuoteStrategy $quoteStrategy |
|
| 553 | 4 | * @return self |
|
| 554 | 4 | * @throws InvalidArgumentException when the provided quote strategy does not fit the expected type |
|
| 555 | 4 | */ |
|
| 556 | public function setQuoteStrategy($quoteStrategy) |
||
| 575 | |||
| 576 | /** |
||
| 577 | * @return string|null|QuoteStrategy |
||
| 578 | */ |
||
| 579 | public function getQuoteStrategy() |
||
| 583 | |||
| 584 | 1 | /** |
|
| 585 | 1 | * @param string|null|RepositoryFactory $repositoryFactory |
|
| 586 | 1 | * @return self |
|
| 587 | 1 | * @throws InvalidArgumentException when the provided repository factory does not fit the expected type |
|
| 588 | 1 | */ |
|
| 589 | public function setRepositoryFactory($repositoryFactory) |
||
| 608 | |||
| 609 | /** |
||
| 610 | * @return string|null|RepositoryFactory |
||
| 611 | */ |
||
| 612 | public function getRepositoryFactory() |
||
| 616 | |||
| 617 | 1 | /** |
|
| 618 | * Set the metadata factory class name to use |
||
| 619 | 1 | * |
|
| 620 | 1 | * @see \Doctrine\ORM\Configuration::setClassMetadataFactoryName() |
|
| 621 | * |
||
| 622 | * @param string $factoryName |
||
| 623 | */ |
||
| 624 | public function setClassMetadataFactoryName($factoryName) |
||
| 628 | |||
| 629 | /** |
||
| 630 | * @return string |
||
| 631 | */ |
||
| 632 | public function getClassMetadataFactoryName() |
||
| 636 | 3 | ||
| 637 | /** |
||
| 638 | 3 | * @param string|null|EntityListenerResolver $entityListenerResolver |
|
| 639 | 3 | * @return self |
|
| 640 | 3 | * @throws InvalidArgumentException When the provided entity listener resolver |
|
| 641 | 3 | * does not fit the expected type |
|
| 642 | 3 | */ |
|
| 643 | public function setEntityListenerResolver($entityListenerResolver) |
||
| 660 | |||
| 661 | /** |
||
| 662 | * @return string|null|EntityListenerResolver |
||
| 663 | */ |
||
| 664 | public function getEntityListenerResolver() |
||
| 668 | 73 | ||
| 669 | 73 | /** |
|
| 670 | * @param array $secondLevelCache |
||
| 671 | * @return void |
||
| 672 | */ |
||
| 673 | public function setSecondLevelCache(array $secondLevelCache) |
||
| 677 | |||
| 678 | /** |
||
| 679 | * @return SecondLevelCacheConfiguration |
||
| 680 | */ |
||
| 681 | public function getSecondLevelCache() |
||
| 685 | 73 | ||
| 686 | /** |
||
| 687 | 73 | * @param string $schemaFilter |
|
| 688 | 73 | * @return void |
|
| 689 | */ |
||
| 690 | public function setSchemaFilter($schemaFilter) |
||
| 694 | |||
| 695 | 86 | /** |
|
| 696 | * @return string|null |
||
| 697 | 86 | */ |
|
| 698 | public function getSchemaFilter() |
||
| 702 | |||
| 703 | /** |
||
| 704 | * Sets default repository class. |
||
| 705 | * |
||
| 706 | * @param string $className |
||
| 707 | * @return void |
||
| 708 | */ |
||
| 709 | public function setDefaultRepositoryClassName($className) |
||
| 713 | |||
| 714 | /** |
||
| 715 | * Get default repository class name. |
||
| 716 | * |
||
| 717 | * @return string|null |
||
| 718 | */ |
||
| 719 | public function getDefaultRepositoryClassName() |
||
| 723 | } |
||
| 724 |