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 | */ |
||
210 | protected $schemaFilter; |
||
211 | |||
212 | /** |
||
213 | * @param array $datetimeFunctions |
||
214 | * @return self |
||
215 | */ |
||
216 | 72 | public function setDatetimeFunctions($datetimeFunctions) |
|
222 | |||
223 | /** |
||
224 | * @return array |
||
225 | */ |
||
226 | 88 | public function getDatetimeFunctions() |
|
230 | |||
231 | /** |
||
232 | * @param string $driver |
||
233 | * @return self |
||
234 | */ |
||
235 | 72 | public function setDriver($driver) |
|
241 | |||
242 | /** |
||
243 | * @return string |
||
244 | */ |
||
245 | 88 | 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 | 88 | public function getEntityNamespaces() |
|
268 | |||
269 | /** |
||
270 | * @param boolean $generateProxies |
||
271 | * @return self |
||
272 | */ |
||
273 | 72 | public function setGenerateProxies($generateProxies) |
|
279 | |||
280 | /** |
||
281 | * @return boolean |
||
282 | */ |
||
283 | 88 | public function getGenerateProxies() |
|
287 | |||
288 | /** |
||
289 | * @param string $metadataCache |
||
290 | * @return self |
||
291 | */ |
||
292 | 72 | public function setMetadataCache($metadataCache) |
|
298 | |||
299 | /** |
||
300 | * @return string |
||
301 | */ |
||
302 | 88 | public function getMetadataCache() |
|
306 | |||
307 | /** |
||
308 | * @param string $resultCache |
||
309 | * @return self |
||
310 | */ |
||
311 | 73 | public function setResultCache($resultCache) |
|
317 | |||
318 | /** |
||
319 | * @return string |
||
320 | */ |
||
321 | 88 | public function getResultCache() |
|
325 | |||
326 | /** |
||
327 | * @param string $hydrationCache |
||
328 | * @return self |
||
329 | */ |
||
330 | 74 | public function setHydrationCache($hydrationCache) |
|
336 | |||
337 | /** |
||
338 | * @return string |
||
339 | */ |
||
340 | 88 | 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 | 88 | 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 | 88 | public function getNamedQueries() |
|
382 | |||
383 | /** |
||
384 | * @param array $numericFunctions |
||
385 | * @return self |
||
386 | */ |
||
387 | 72 | public function setNumericFunctions($numericFunctions) |
|
393 | |||
394 | /** |
||
395 | * @return array |
||
396 | */ |
||
397 | 88 | public function getNumericFunctions() |
|
401 | |||
402 | /** |
||
403 | * |
||
404 | * @param array $filters |
||
405 | * @return self |
||
406 | */ |
||
407 | 72 | public function setFilters($filters) |
|
413 | |||
414 | /** |
||
415 | * |
||
416 | * @return array |
||
417 | */ |
||
418 | 88 | public function getFilters() |
|
422 | |||
423 | /** |
||
424 | * @param string $proxyDir |
||
425 | * @return self |
||
426 | */ |
||
427 | 72 | public function setProxyDir($proxyDir) |
|
433 | |||
434 | /** |
||
435 | * @return string |
||
436 | */ |
||
437 | 88 | public function getProxyDir() |
|
441 | |||
442 | /** |
||
443 | * @param string $proxyNamespace |
||
444 | * @return self |
||
445 | */ |
||
446 | 72 | public function setProxyNamespace($proxyNamespace) |
|
452 | |||
453 | /** |
||
454 | * @return string |
||
455 | */ |
||
456 | 88 | public function getProxyNamespace() |
|
460 | |||
461 | /** |
||
462 | * @param string $queryCache |
||
463 | * @return self |
||
464 | */ |
||
465 | 72 | public function setQueryCache($queryCache) |
|
471 | |||
472 | /** |
||
473 | * @return string |
||
474 | */ |
||
475 | 88 | public function getQueryCache() |
|
479 | |||
480 | /** |
||
481 | * @param array $stringFunctions |
||
482 | * @return self |
||
483 | */ |
||
484 | 72 | public function setStringFunctions($stringFunctions) |
|
490 | |||
491 | /** |
||
492 | * @return array |
||
493 | */ |
||
494 | 88 | 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 | 88 | public function getCustomHydrationModes() |
|
517 | |||
518 | /** |
||
519 | * @param string|null|NamingStrategy $namingStrategy |
||
520 | * @return self |
||
521 | * @throws InvalidArgumentException when the provided naming strategy does not fit the expected type |
||
522 | */ |
||
523 | 4 | public function setNamingStrategy($namingStrategy) |
|
542 | |||
543 | /** |
||
544 | * @return string|null|NamingStrategy |
||
545 | */ |
||
546 | 89 | public function getNamingStrategy() |
|
550 | |||
551 | /** |
||
552 | * @param string|null|QuoteStrategy $quoteStrategy |
||
553 | * @return self |
||
554 | * @throws InvalidArgumentException when the provided quote strategy does not fit the expected type |
||
555 | */ |
||
556 | 4 | public function setQuoteStrategy($quoteStrategy) |
|
575 | |||
576 | /** |
||
577 | * @return string|null|QuoteStrategy |
||
578 | */ |
||
579 | 88 | public function getQuoteStrategy() |
|
583 | |||
584 | /** |
||
585 | * @param string|null|RepositoryFactory $repositoryFactory |
||
586 | * @return self |
||
587 | * @throws InvalidArgumentException when the provided repository factory does not fit the expected type |
||
588 | */ |
||
589 | 1 | public function setRepositoryFactory($repositoryFactory) |
|
608 | |||
609 | /** |
||
610 | * @return string|null|RepositoryFactory |
||
611 | */ |
||
612 | 87 | public function getRepositoryFactory() |
|
616 | |||
617 | /** |
||
618 | * Set the metadata factory class name to use |
||
619 | * |
||
620 | * @see \Doctrine\ORM\Configuration::setClassMetadataFactoryName() |
||
621 | * |
||
622 | * @param string $factoryName |
||
623 | */ |
||
624 | 1 | public function setClassMetadataFactoryName($factoryName) |
|
628 | |||
629 | /** |
||
630 | * @return string |
||
631 | */ |
||
632 | 88 | public function getClassMetadataFactoryName() |
|
636 | |||
637 | /** |
||
638 | * @param string|null|EntityListenerResolver $entityListenerResolver |
||
639 | * @return self |
||
640 | * @throws InvalidArgumentException When the provided entity listener resolver |
||
641 | * does not fit the expected type |
||
642 | */ |
||
643 | 3 | public function setEntityListenerResolver($entityListenerResolver) |
|
660 | |||
661 | /** |
||
662 | * @return string|null|EntityListenerResolver |
||
663 | */ |
||
664 | 87 | public function getEntityListenerResolver() |
|
668 | |||
669 | /** |
||
670 | * @param array $secondLevelCache |
||
671 | * @return void |
||
672 | */ |
||
673 | 73 | public function setSecondLevelCache(array $secondLevelCache) |
|
677 | |||
678 | /** |
||
679 | * @return SecondLevelCacheConfiguration |
||
680 | */ |
||
681 | 86 | public function getSecondLevelCache() |
|
685 | |||
686 | /** |
||
687 | * @param string $schemaFilter |
||
688 | * @return void |
||
689 | */ |
||
690 | public function setSchemaFilter($schemaFilter) |
||
694 | |||
695 | /** |
||
696 | * @return string|null |
||
697 | */ |
||
698 | 86 | public function getSchemaFilter() |
|
702 | |||
703 | /** |
||
704 | * Sets default repository class. |
||
705 | * |
||
706 | * @param string $className |
||
707 | * @return void |
||
708 | */ |
||
709 | 73 | public function setDefaultRepositoryClassName($className) |
|
713 | |||
714 | /** |
||
715 | * Get default repository class name. |
||
716 | * |
||
717 | * @return string|null |
||
718 | */ |
||
719 | 86 | public function getDefaultRepositoryClassName() |
|
723 | } |
||
724 |