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 |
||
21 | class Configuration extends DBALConfiguration |
||
22 | { |
||
23 | /** |
||
24 | * Set the cache key for the metadata cache. Cache key |
||
25 | * is assembled as "doctrine.cache.{key}" and pulled from |
||
26 | * service locator. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $metadataCache = 'array'; |
||
31 | |||
32 | /** |
||
33 | * Set the cache key for the query cache. Cache key |
||
34 | * is assembled as "doctrine.cache.{key}" and pulled from |
||
35 | * service locator. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $queryCache = 'array'; |
||
40 | |||
41 | /** |
||
42 | * Set the cache key for the result cache. Cache key |
||
43 | * is assembled as "doctrine.cache.{key}" and pulled from |
||
44 | * service locator. |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $resultCache = 'array'; |
||
49 | |||
50 | /** |
||
51 | * Set the cache key for the hydration cache. Cache key |
||
52 | * is assembled as "doctrine.cache.{key}" and pulled from |
||
53 | * service locator. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $hydrationCache = 'array'; |
||
58 | |||
59 | /** |
||
60 | * Set the driver key for the metadata driver. Driver key |
||
61 | * is assembled as "doctrine.driver.{key}" and pulled from |
||
62 | * service locator. |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $driver = 'orm_default'; |
||
67 | |||
68 | /** |
||
69 | * Automatic generation of proxies (disable for production!) |
||
70 | * |
||
71 | * @var bool |
||
72 | */ |
||
73 | protected $generateProxies = true; |
||
74 | |||
75 | /** |
||
76 | * Proxy directory. |
||
77 | * |
||
78 | * @var string |
||
79 | */ |
||
80 | protected $proxyDir = 'data'; |
||
81 | |||
82 | /** |
||
83 | * Proxy namespace. |
||
84 | * |
||
85 | * @var string |
||
86 | */ |
||
87 | protected $proxyNamespace = 'DoctrineORMModule\Proxy'; |
||
88 | |||
89 | /** |
||
90 | * Entity alias map. |
||
91 | * |
||
92 | * @var mixed[] |
||
93 | */ |
||
94 | protected $entityNamespaces = []; |
||
95 | |||
96 | /** |
||
97 | * Keys must be function names and values the FQCN of the implementing class. |
||
98 | * The function names will be case-insensitive in DQL. |
||
99 | * |
||
100 | * @var mixed[] |
||
101 | */ |
||
102 | protected $datetimeFunctions = []; |
||
103 | |||
104 | /** |
||
105 | * Keys must be function names and values the FQCN of the implementing class. |
||
106 | * The function names will be case-insensitive in DQL. |
||
107 | * |
||
108 | * @var mixed[] |
||
109 | */ |
||
110 | protected $stringFunctions = []; |
||
111 | |||
112 | /** |
||
113 | * Keys must be function names and values the FQCN of the implementing class. |
||
114 | * The function names will be case-insensitive in DQL. |
||
115 | * |
||
116 | * @var mixed[] |
||
117 | */ |
||
118 | protected $numericFunctions = []; |
||
119 | |||
120 | /** |
||
121 | * Keys must be the name of the custom filter and the value must be |
||
122 | * the class name for the custom filter. |
||
123 | * |
||
124 | * @var mixed[] |
||
125 | */ |
||
126 | protected $filters = []; |
||
127 | |||
128 | /** |
||
129 | * Keys must be the name of the query and values the DQL query string. |
||
130 | * |
||
131 | * @var mixed[] |
||
132 | */ |
||
133 | protected $namedQueries = []; |
||
134 | |||
135 | /** |
||
136 | * Keys must be the name of the query and the value is an array containing |
||
137 | * the keys 'sql' for native SQL query string and 'rsm' for the Query\ResultSetMapping. |
||
138 | * |
||
139 | * @var mixed[] |
||
140 | */ |
||
141 | protected $namedNativeQueries = []; |
||
142 | |||
143 | /** |
||
144 | * Keys must be the name of the custom hydration method and the value must be |
||
145 | * the class name for the custom hydrator |
||
146 | * |
||
147 | * @var mixed[] |
||
148 | */ |
||
149 | protected $customHydrationModes = []; |
||
150 | |||
151 | /** |
||
152 | * Naming strategy or name of the naming strategy service to be set in ORM |
||
153 | * configuration (if any) |
||
154 | * |
||
155 | * @var string|NamingStrategy|null |
||
156 | */ |
||
157 | protected $namingStrategy; |
||
158 | |||
159 | /** |
||
160 | * Quote strategy or name of the quote strategy service to be set in ORM |
||
161 | * configuration (if any) |
||
162 | * |
||
163 | * @var string|QuoteStrategy|null |
||
164 | */ |
||
165 | protected $quoteStrategy; |
||
166 | |||
167 | /** |
||
168 | * Default repository class |
||
169 | * |
||
170 | * @var string|null |
||
171 | */ |
||
172 | protected $defaultRepositoryClassName; |
||
173 | |||
174 | /** |
||
175 | * Repository factory or name of the repository factory service to be set in ORM |
||
176 | * configuration (if any) |
||
177 | * |
||
178 | * @var string|RepositoryFactory|null |
||
179 | */ |
||
180 | protected $repositoryFactory; |
||
181 | |||
182 | /** |
||
183 | * Class name of MetaData factory to be set in ORM. |
||
184 | * The entityManager will create a new instance on construction. |
||
185 | * |
||
186 | * @var string |
||
187 | */ |
||
188 | protected $classMetadataFactoryName; |
||
189 | |||
190 | /** |
||
191 | * Entity listener resolver or service name of the entity listener resolver |
||
192 | * to be set in ORM configuration (if any) |
||
193 | * |
||
194 | * @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html |
||
195 | * |
||
196 | * @var string|EntityListenerResolver|null |
||
197 | */ |
||
198 | protected $entityListenerResolver; |
||
199 | |||
200 | /** |
||
201 | * Configuration for second level cache |
||
202 | * |
||
203 | * @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/second-level-cache.html |
||
204 | * |
||
205 | * @var SecondLevelCacheConfiguration|null |
||
206 | */ |
||
207 | protected $secondLevelCache; |
||
208 | |||
209 | /** |
||
210 | * Configuration option for the filter schema assets expression |
||
211 | * |
||
212 | * @var string|null |
||
213 | */ |
||
214 | protected $filterSchemaAssetsExpression; |
||
215 | |||
216 | /** |
||
217 | * @param mixed[] $datetimeFunctions |
||
218 | */ |
||
219 | 72 | public function setDatetimeFunctions(array $datetimeFunctions) : self |
|
220 | { |
||
221 | 72 | $this->datetimeFunctions = $datetimeFunctions; |
|
222 | |||
223 | 72 | return $this; |
|
224 | } |
||
225 | |||
226 | /** |
||
227 | * @return mixed[] |
||
228 | */ |
||
229 | 88 | public function getDatetimeFunctions() : array |
|
230 | { |
||
231 | 88 | return $this->datetimeFunctions; |
|
232 | } |
||
233 | |||
234 | 72 | public function setDriver(string $driver) : self |
|
235 | { |
||
236 | 72 | $this->driver = $driver; |
|
237 | |||
238 | 72 | return $this; |
|
239 | } |
||
240 | |||
241 | 88 | public function getDriver() : string |
|
242 | { |
||
243 | 88 | return 'doctrine.driver.' . $this->driver; |
|
244 | } |
||
245 | |||
246 | /** |
||
247 | * @param mixed[] $entityNamespaces |
||
248 | */ |
||
249 | public function setEntityNamespaces(array $entityNamespaces) : self |
||
255 | |||
256 | /** |
||
257 | * @return mixed[] |
||
258 | */ |
||
259 | 88 | public function getEntityNamespaces() : array |
|
263 | |||
264 | 72 | public function setGenerateProxies(bool $generateProxies) : self |
|
265 | { |
||
266 | 72 | $this->generateProxies = $generateProxies; |
|
267 | |||
268 | 72 | return $this; |
|
269 | } |
||
270 | |||
271 | 88 | public function getGenerateProxies() : bool |
|
275 | |||
276 | 72 | public function setMetadataCache(string $metadataCache) : self |
|
277 | { |
||
278 | 72 | $this->metadataCache = $metadataCache; |
|
279 | |||
280 | 72 | return $this; |
|
281 | } |
||
282 | |||
283 | 88 | public function getMetadataCache() : string |
|
287 | |||
288 | 73 | public function setResultCache(string $resultCache) : void |
|
292 | |||
293 | 88 | public function getResultCache() : string |
|
297 | |||
298 | 74 | public function setHydrationCache(string $hydrationCache) : self |
|
304 | |||
305 | 88 | public function getHydrationCache() : string |
|
309 | |||
310 | /** |
||
311 | * @param mixed[] $namedNativeQueries |
||
312 | */ |
||
313 | public function setNamedNativeQueries(array $namedNativeQueries) : self |
||
319 | |||
320 | /** |
||
321 | * @return mixed[] |
||
322 | */ |
||
323 | 88 | public function getNamedNativeQueries() : array |
|
327 | |||
328 | /** |
||
329 | * @param mixed[] $namedQueries |
||
330 | */ |
||
331 | public function setNamedQueries(array $namedQueries) : self |
||
337 | |||
338 | /** |
||
339 | * @return mixed[] |
||
340 | */ |
||
341 | 88 | public function getNamedQueries() : array |
|
345 | |||
346 | /** |
||
347 | * @param mixed[] $numericFunctions |
||
348 | */ |
||
349 | 72 | public function setNumericFunctions(array $numericFunctions) : self |
|
350 | { |
||
351 | 72 | $this->numericFunctions = $numericFunctions; |
|
352 | |||
353 | 72 | return $this; |
|
354 | } |
||
355 | |||
356 | /** |
||
357 | * @return mixed[] |
||
358 | */ |
||
359 | 88 | public function getNumericFunctions() : array |
|
363 | |||
364 | /** |
||
365 | * @param mixed[] $filters |
||
366 | */ |
||
367 | 72 | public function setFilters(array $filters) : self |
|
368 | { |
||
369 | 72 | $this->filters = $filters; |
|
370 | |||
371 | 72 | return $this; |
|
372 | } |
||
373 | |||
374 | /** |
||
375 | * @return mixed[] |
||
376 | */ |
||
377 | 88 | public function getFilters() : array |
|
381 | |||
382 | 72 | public function setProxyDir(string $proxyDir) : self |
|
383 | { |
||
384 | 72 | $this->proxyDir = $proxyDir; |
|
385 | |||
386 | 72 | return $this; |
|
387 | } |
||
388 | |||
389 | 88 | public function getProxyDir() : string |
|
393 | |||
394 | 72 | public function setProxyNamespace(string $proxyNamespace) : self |
|
395 | { |
||
396 | 72 | $this->proxyNamespace = $proxyNamespace; |
|
397 | |||
398 | 72 | return $this; |
|
399 | } |
||
400 | |||
401 | 88 | public function getProxyNamespace() : string |
|
405 | |||
406 | 72 | public function setQueryCache(string $queryCache) : self |
|
407 | { |
||
408 | 72 | $this->queryCache = $queryCache; |
|
409 | |||
410 | 72 | return $this; |
|
411 | } |
||
412 | |||
413 | 88 | public function getQueryCache() : string |
|
417 | |||
418 | /** |
||
419 | * @param mixed[] $stringFunctions |
||
420 | */ |
||
421 | 72 | public function setStringFunctions(array $stringFunctions) : self |
|
422 | { |
||
423 | 72 | $this->stringFunctions = $stringFunctions; |
|
424 | |||
425 | 72 | return $this; |
|
426 | } |
||
427 | |||
428 | /** |
||
429 | * @return mixed[] |
||
430 | */ |
||
431 | 88 | public function getStringFunctions() : array |
|
435 | |||
436 | /** |
||
437 | * @param mixed[] $modes |
||
438 | */ |
||
439 | public function setCustomHydrationModes(array $modes) : self |
||
445 | |||
446 | /** |
||
447 | * @return mixed[] |
||
448 | */ |
||
449 | 88 | public function getCustomHydrationModes() : array |
|
453 | |||
454 | /** |
||
455 | * @param string|NamingStrategy|null $namingStrategy |
||
456 | * |
||
457 | * @throws InvalidArgumentException when the provided naming strategy does not fit the expected type. |
||
458 | */ |
||
459 | 4 | public function setNamingStrategy($namingStrategy) : self |
|
478 | |||
479 | /** |
||
480 | * @return string|NamingStrategy|null |
||
481 | */ |
||
482 | 89 | public function getNamingStrategy() |
|
486 | |||
487 | /** |
||
488 | * @param string|QuoteStrategy|null $quoteStrategy |
||
489 | * |
||
490 | * @throws InvalidArgumentException when the provided quote strategy does not fit the expected type. |
||
491 | */ |
||
492 | 4 | public function setQuoteStrategy($quoteStrategy) : self |
|
511 | |||
512 | /** |
||
513 | * @return string|QuoteStrategy|null |
||
514 | */ |
||
515 | 88 | public function getQuoteStrategy() |
|
519 | |||
520 | /** |
||
521 | * @param string|RepositoryFactory|null $repositoryFactory |
||
522 | * |
||
523 | * @throws InvalidArgumentException when the provided repository factory does not fit the expected type. |
||
524 | */ |
||
525 | 1 | public function setRepositoryFactory($repositoryFactory) : self |
|
544 | |||
545 | /** |
||
546 | * @return string|RepositoryFactory|null |
||
547 | */ |
||
548 | 87 | public function getRepositoryFactory() |
|
552 | |||
553 | /** |
||
554 | * Set the metadata factory class name to use |
||
555 | * |
||
556 | * @see \Doctrine\ORM\Configuration::setClassMetadataFactoryName() |
||
557 | */ |
||
558 | 1 | public function setClassMetadataFactoryName(string $factoryName) : self |
|
564 | |||
565 | 88 | public function getClassMetadataFactoryName() : ?string |
|
569 | |||
570 | /** |
||
571 | * @param string|EntityListenerResolver|null $entityListenerResolver |
||
572 | * |
||
573 | * @throws InvalidArgumentException When the provided entity listener resolver |
||
574 | * does not fit the expected type. |
||
575 | */ |
||
576 | 3 | public function setEntityListenerResolver($entityListenerResolver) : self |
|
593 | |||
594 | /** |
||
595 | * @return string|EntityListenerResolver|null |
||
596 | */ |
||
597 | 87 | public function getEntityListenerResolver() |
|
601 | |||
602 | /** |
||
603 | * @param mixed[] $secondLevelCache |
||
604 | */ |
||
605 | 73 | public function setSecondLevelCache(array $secondLevelCache) : self |
|
611 | |||
612 | 86 | public function getSecondLevelCache() : SecondLevelCacheConfiguration |
|
616 | |||
617 | public function setFilterSchemaAssetsExpression(string $filterSchemaAssetsExpression) : self |
||
623 | |||
624 | 86 | public function getFilterSchemaAssetsExpression() : ?string |
|
628 | |||
629 | /** |
||
630 | * Sets default repository class. |
||
631 | */ |
||
632 | 73 | public function setDefaultRepositoryClassName(string $className) : self |
|
638 | |||
639 | /** |
||
640 | * Get default repository class name. |
||
641 | */ |
||
642 | 86 | public function getDefaultRepositoryClassName() : ?string |
|
646 | } |
||
647 |