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 = array(); |
||
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 = array(); |
||
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 = array(); |
||
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 = array(); |
||
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 = array(); |
||
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 = array(); |
||
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 = array(); |
||
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 = array(); |
||
148 | |||
149 | /** |
||
150 | * Keys must be the name of the custom query hint and the value must be |
||
151 | * the class name for the custom walker |
||
152 | * |
||
153 | * @var array |
||
154 | */ |
||
155 | protected $defaultQueryHints = array(); |
||
156 | |||
157 | /** |
||
158 | * Naming strategy or name of the naming strategy service to be set in ORM |
||
159 | * configuration (if any) |
||
160 | * |
||
161 | * @var string|null|NamingStrategy |
||
162 | */ |
||
163 | protected $namingStrategy; |
||
164 | |||
165 | /** |
||
166 | * Quote strategy or name of the quote strategy service to be set in ORM |
||
167 | * configuration (if any) |
||
168 | * |
||
169 | * @var string|null|QuoteStrategy |
||
170 | */ |
||
171 | protected $quoteStrategy; |
||
172 | |||
173 | /** |
||
174 | * Default repository class |
||
175 | * |
||
176 | * @var string|null |
||
177 | */ |
||
178 | protected $defaultRepositoryClassName; |
||
179 | |||
180 | /** |
||
181 | * Repository factory or name of the repository factory service to be set in ORM |
||
182 | * configuration (if any) |
||
183 | * |
||
184 | * @var string|null|RepositoryFactory |
||
185 | */ |
||
186 | protected $repositoryFactory; |
||
187 | |||
188 | /** |
||
189 | * Class name of MetaData factory to be set in ORM. |
||
190 | * The entityManager will create a new instance on construction. |
||
191 | * |
||
192 | * @var string |
||
193 | */ |
||
194 | protected $classMetadataFactoryName; |
||
195 | |||
196 | /** |
||
197 | * Entity listener resolver or service name of the entity listener resolver |
||
198 | * to be set in ORM configuration (if any) |
||
199 | * |
||
200 | * @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html |
||
201 | * @var string|null|EntityListenerResolver |
||
202 | */ |
||
203 | protected $entityListenerResolver; |
||
204 | |||
205 | /** |
||
206 | * Configuration for second level cache |
||
207 | * |
||
208 | * @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/second-level-cache.html |
||
209 | * @var SecondLevelCacheConfiguration|null |
||
210 | */ |
||
211 | protected $secondLevelCache; |
||
212 | |||
213 | /** |
||
214 | * @param array $datetimeFunctions |
||
215 | * @return self |
||
216 | */ |
||
217 | 56 | public function setDatetimeFunctions($datetimeFunctions) |
|
223 | |||
224 | /** |
||
225 | * @return array |
||
226 | */ |
||
227 | 72 | public function getDatetimeFunctions() |
|
231 | |||
232 | /** |
||
233 | * @param string $driver |
||
234 | * @return self |
||
235 | */ |
||
236 | 56 | public function setDriver($driver) |
|
242 | |||
243 | /** |
||
244 | * @return string |
||
245 | */ |
||
246 | 72 | public function getDriver() |
|
250 | |||
251 | /** |
||
252 | * @param array $entityNamespaces |
||
253 | * @return self |
||
254 | */ |
||
255 | public function setEntityNamespaces($entityNamespaces) |
||
261 | |||
262 | /** |
||
263 | * @return array |
||
264 | */ |
||
265 | 72 | public function getEntityNamespaces() |
|
269 | |||
270 | /** |
||
271 | * @param boolean $generateProxies |
||
272 | * @return self |
||
273 | */ |
||
274 | 56 | public function setGenerateProxies($generateProxies) |
|
280 | |||
281 | /** |
||
282 | * @return boolean |
||
283 | */ |
||
284 | 72 | public function getGenerateProxies() |
|
288 | |||
289 | /** |
||
290 | * @param string $metadataCache |
||
291 | * @return self |
||
292 | */ |
||
293 | 56 | public function setMetadataCache($metadataCache) |
|
299 | |||
300 | /** |
||
301 | * @return string |
||
302 | */ |
||
303 | 72 | public function getMetadataCache() |
|
307 | |||
308 | /** |
||
309 | * @param string $resultCache |
||
310 | * @return self |
||
311 | */ |
||
312 | 57 | public function setResultCache($resultCache) |
|
318 | |||
319 | /** |
||
320 | * @return string |
||
321 | */ |
||
322 | 72 | public function getResultCache() |
|
326 | |||
327 | /** |
||
328 | * @param string $hydrationCache |
||
329 | * @return self |
||
330 | */ |
||
331 | 58 | public function setHydrationCache($hydrationCache) |
|
337 | |||
338 | /** |
||
339 | * @return string |
||
340 | */ |
||
341 | 72 | public function getHydrationCache() |
|
345 | |||
346 | /** |
||
347 | * @param array $namedNativeQueries |
||
348 | * @return self |
||
349 | */ |
||
350 | public function setNamedNativeQueries($namedNativeQueries) |
||
356 | |||
357 | /** |
||
358 | * @return array |
||
359 | */ |
||
360 | 72 | public function getNamedNativeQueries() |
|
364 | |||
365 | /** |
||
366 | * @param array $namedQueries |
||
367 | * @return self |
||
368 | */ |
||
369 | public function setNamedQueries($namedQueries) |
||
375 | |||
376 | /** |
||
377 | * @return array |
||
378 | */ |
||
379 | 72 | public function getNamedQueries() |
|
383 | |||
384 | /** |
||
385 | * @param array $numericFunctions |
||
386 | * @return self |
||
387 | */ |
||
388 | 56 | public function setNumericFunctions($numericFunctions) |
|
394 | |||
395 | /** |
||
396 | * @return array |
||
397 | */ |
||
398 | 72 | public function getNumericFunctions() |
|
402 | |||
403 | /** |
||
404 | * |
||
405 | * @param array $filters |
||
406 | * @return self |
||
407 | */ |
||
408 | 56 | public function setFilters($filters) |
|
414 | |||
415 | /** |
||
416 | * |
||
417 | * @return array |
||
418 | */ |
||
419 | 72 | public function getFilters() |
|
423 | |||
424 | /** |
||
425 | * @param string $proxyDir |
||
426 | * @return self |
||
427 | */ |
||
428 | 56 | public function setProxyDir($proxyDir) |
|
434 | |||
435 | /** |
||
436 | * @return string |
||
437 | */ |
||
438 | 72 | public function getProxyDir() |
|
442 | |||
443 | /** |
||
444 | * @param string $proxyNamespace |
||
445 | * @return self |
||
446 | */ |
||
447 | 56 | public function setProxyNamespace($proxyNamespace) |
|
453 | |||
454 | /** |
||
455 | * @return string |
||
456 | */ |
||
457 | 72 | public function getProxyNamespace() |
|
461 | |||
462 | /** |
||
463 | * @param string $queryCache |
||
464 | * @return self |
||
465 | */ |
||
466 | 56 | public function setQueryCache($queryCache) |
|
472 | |||
473 | /** |
||
474 | * @return string |
||
475 | */ |
||
476 | 72 | public function getQueryCache() |
|
480 | |||
481 | /** |
||
482 | * @param array $stringFunctions |
||
483 | * @return self |
||
484 | */ |
||
485 | 56 | public function setStringFunctions($stringFunctions) |
|
491 | |||
492 | /** |
||
493 | * @return array |
||
494 | */ |
||
495 | 72 | public function getStringFunctions() |
|
499 | |||
500 | /** |
||
501 | * @param array $modes |
||
502 | * @return self |
||
503 | */ |
||
504 | public function setCustomHydrationModes($modes) |
||
510 | |||
511 | /** |
||
512 | * @return array |
||
513 | */ |
||
514 | 72 | public function getCustomHydrationModes() |
|
518 | |||
519 | /** |
||
520 | * @param string|null|NamingStrategy $namingStrategy |
||
521 | * @return self |
||
522 | * @throws InvalidArgumentException when the provided naming strategy does not fit the expected type |
||
523 | */ |
||
524 | 4 | public function setNamingStrategy($namingStrategy) |
|
543 | |||
544 | /** |
||
545 | * @return string|null|NamingStrategy |
||
546 | */ |
||
547 | 73 | public function getNamingStrategy() |
|
551 | |||
552 | /** |
||
553 | * @param string|null|QuoteStrategy $quoteStrategy |
||
554 | * @return self |
||
555 | * @throws InvalidArgumentException when the provided quote strategy does not fit the expected type |
||
556 | */ |
||
557 | 4 | public function setQuoteStrategy($quoteStrategy) |
|
576 | |||
577 | /** |
||
578 | * @return string|null|QuoteStrategy |
||
579 | */ |
||
580 | 72 | public function getQuoteStrategy() |
|
584 | |||
585 | /** |
||
586 | * @param string|null|RepositoryFactory $repositoryFactory |
||
587 | * @return self |
||
588 | * @throws InvalidArgumentException when the provided repository factory does not fit the expected type |
||
589 | */ |
||
590 | 1 | public function setRepositoryFactory($repositoryFactory) |
|
609 | |||
610 | /** |
||
611 | * @return string|null|RepositoryFactory |
||
612 | */ |
||
613 | 71 | public function getRepositoryFactory() |
|
617 | |||
618 | /** |
||
619 | * Set the metadata factory class name to use |
||
620 | * |
||
621 | * @see \Doctrine\ORM\Configuration::setClassMetadataFactoryName() |
||
622 | * |
||
623 | * @param string $factoryName |
||
624 | */ |
||
625 | 1 | public function setClassMetadataFactoryName($factoryName) |
|
629 | |||
630 | /** |
||
631 | * @return string |
||
632 | */ |
||
633 | 72 | public function getClassMetadataFactoryName() |
|
637 | |||
638 | /** |
||
639 | * @param string|null|EntityListenerResolver $entityListenerResolver |
||
640 | * @return self |
||
641 | * @throws InvalidArgumentException When the provided entity listener resolver |
||
642 | * does not fit the expected type |
||
643 | */ |
||
644 | 3 | public function setEntityListenerResolver($entityListenerResolver) |
|
661 | |||
662 | /** |
||
663 | * @return string|null|EntityListenerResolver |
||
664 | */ |
||
665 | 71 | public function getEntityListenerResolver() |
|
669 | |||
670 | /** |
||
671 | * @param array $secondLevelCache |
||
672 | * @return void |
||
673 | */ |
||
674 | 57 | public function setSecondLevelCache(array $secondLevelCache) |
|
678 | |||
679 | /** |
||
680 | * @return SecondLevelCacheConfiguration |
||
681 | */ |
||
682 | 70 | public function getSecondLevelCache() |
|
686 | |||
687 | /** |
||
688 | * Sets default repository class. |
||
689 | * |
||
690 | * @param string $className |
||
691 | * @return void |
||
692 | */ |
||
693 | 57 | public function setDefaultRepositoryClassName($className) |
|
697 | |||
698 | /** |
||
699 | * Get default repository class name. |
||
700 | * |
||
701 | * @return string|null |
||
702 | */ |
||
703 | 70 | public function getDefaultRepositoryClassName() |
|
707 | |||
708 | /** |
||
709 | * Get default query hints |
||
710 | * |
||
711 | * @return array |
||
712 | */ |
||
713 | 73 | public function getDefaultQueryHints() |
|
717 | |||
718 | /** |
||
719 | * Set default query hints |
||
720 | * |
||
721 | * @param array $defaultQueryHints |
||
722 | */ |
||
723 | 57 | public function setDefaultQueryHints($defaultQueryHints) |
|
727 | } |
||
728 |