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 | * 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 | * @param array $datetimeFunctions |
||
207 | * @return self |
||
208 | */ |
||
209 | 56 | public function setDatetimeFunctions($datetimeFunctions) |
|
210 | { |
||
211 | 56 | $this->datetimeFunctions = $datetimeFunctions; |
|
212 | |||
213 | 56 | return $this; |
|
214 | } |
||
215 | |||
216 | /** |
||
217 | * @return array |
||
218 | */ |
||
219 | 72 | public function getDatetimeFunctions() |
|
220 | { |
||
221 | 72 | return $this->datetimeFunctions; |
|
222 | } |
||
223 | |||
224 | /** |
||
225 | * @param string $driver |
||
226 | * @return self |
||
227 | */ |
||
228 | 56 | public function setDriver($driver) |
|
229 | { |
||
230 | 56 | $this->driver = $driver; |
|
231 | |||
232 | 56 | return $this; |
|
233 | } |
||
234 | |||
235 | /** |
||
236 | * @return string |
||
237 | */ |
||
238 | 72 | public function getDriver() |
|
239 | { |
||
240 | 72 | return "doctrine.driver.{$this->driver}"; |
|
241 | } |
||
242 | |||
243 | /** |
||
244 | * @param array $entityNamespaces |
||
245 | * @return self |
||
246 | */ |
||
247 | public function setEntityNamespaces($entityNamespaces) |
||
248 | { |
||
249 | $this->entityNamespaces = $entityNamespaces; |
||
250 | |||
251 | return $this; |
||
252 | } |
||
253 | |||
254 | /** |
||
255 | * @return array |
||
256 | */ |
||
257 | 72 | public function getEntityNamespaces() |
|
258 | { |
||
259 | 72 | return $this->entityNamespaces; |
|
260 | } |
||
261 | |||
262 | /** |
||
263 | * @param boolean $generateProxies |
||
264 | * @return self |
||
265 | */ |
||
266 | 56 | public function setGenerateProxies($generateProxies) |
|
267 | { |
||
268 | 56 | $this->generateProxies = $generateProxies; |
|
269 | |||
270 | 56 | return $this; |
|
271 | } |
||
272 | |||
273 | /** |
||
274 | * @return boolean |
||
275 | */ |
||
276 | 72 | public function getGenerateProxies() |
|
277 | { |
||
278 | 72 | return $this->generateProxies; |
|
279 | } |
||
280 | |||
281 | /** |
||
282 | * @param string $metadataCache |
||
283 | * @return self |
||
284 | */ |
||
285 | 56 | public function setMetadataCache($metadataCache) |
|
286 | { |
||
287 | 56 | $this->metadataCache = $metadataCache; |
|
288 | |||
289 | 56 | return $this; |
|
290 | } |
||
291 | |||
292 | /** |
||
293 | * @return string |
||
294 | */ |
||
295 | 72 | public function getMetadataCache() |
|
296 | { |
||
297 | 72 | return "doctrine.cache.{$this->metadataCache}"; |
|
298 | } |
||
299 | |||
300 | /** |
||
301 | * @param string $resultCache |
||
302 | * @return self |
||
303 | */ |
||
304 | 57 | public function setResultCache($resultCache) |
|
305 | { |
||
306 | 57 | $this->resultCache = $resultCache; |
|
307 | |||
308 | 57 | return $this; |
|
309 | } |
||
310 | |||
311 | /** |
||
312 | * @return string |
||
313 | */ |
||
314 | 72 | public function getResultCache() |
|
315 | { |
||
316 | 72 | return "doctrine.cache.{$this->resultCache}"; |
|
317 | } |
||
318 | |||
319 | /** |
||
320 | * @param string $hydrationCache |
||
321 | * @return self |
||
322 | */ |
||
323 | 58 | public function setHydrationCache($hydrationCache) |
|
324 | { |
||
325 | 58 | $this->hydrationCache = $hydrationCache; |
|
326 | |||
327 | 58 | return $this; |
|
328 | } |
||
329 | |||
330 | /** |
||
331 | * @return string |
||
332 | */ |
||
333 | 72 | public function getHydrationCache() |
|
334 | { |
||
335 | 72 | return "doctrine.cache.{$this->hydrationCache}"; |
|
336 | } |
||
337 | |||
338 | /** |
||
339 | * @param array $namedNativeQueries |
||
340 | * @return self |
||
341 | */ |
||
342 | public function setNamedNativeQueries($namedNativeQueries) |
||
343 | { |
||
344 | $this->namedNativeQueries = $namedNativeQueries; |
||
345 | |||
346 | return $this; |
||
347 | } |
||
348 | |||
349 | /** |
||
350 | * @return array |
||
351 | */ |
||
352 | 72 | public function getNamedNativeQueries() |
|
353 | { |
||
354 | 72 | return $this->namedNativeQueries; |
|
355 | } |
||
356 | |||
357 | /** |
||
358 | * @param array $namedQueries |
||
359 | * @return self |
||
360 | */ |
||
361 | public function setNamedQueries($namedQueries) |
||
362 | { |
||
363 | $this->namedQueries = $namedQueries; |
||
364 | |||
365 | return $this; |
||
366 | } |
||
367 | |||
368 | /** |
||
369 | * @return array |
||
370 | */ |
||
371 | 72 | public function getNamedQueries() |
|
372 | { |
||
373 | 72 | return $this->namedQueries; |
|
374 | } |
||
375 | |||
376 | /** |
||
377 | * @param array $numericFunctions |
||
378 | * @return self |
||
379 | */ |
||
380 | 56 | public function setNumericFunctions($numericFunctions) |
|
381 | { |
||
382 | 56 | $this->numericFunctions = $numericFunctions; |
|
383 | |||
384 | 56 | return $this; |
|
385 | } |
||
386 | |||
387 | /** |
||
388 | * @return array |
||
389 | */ |
||
390 | 72 | public function getNumericFunctions() |
|
391 | { |
||
392 | 72 | return $this->numericFunctions; |
|
393 | } |
||
394 | |||
395 | /** |
||
396 | * |
||
397 | * @param array $filters |
||
398 | * @return self |
||
399 | */ |
||
400 | 56 | public function setFilters($filters) |
|
401 | { |
||
402 | 56 | $this->filters = $filters; |
|
403 | |||
404 | 56 | return $this; |
|
405 | } |
||
406 | |||
407 | /** |
||
408 | * |
||
409 | * @return array |
||
410 | */ |
||
411 | 72 | public function getFilters() |
|
412 | { |
||
413 | 72 | return $this->filters; |
|
414 | } |
||
415 | |||
416 | /** |
||
417 | * @param string $proxyDir |
||
418 | * @return self |
||
419 | */ |
||
420 | 56 | public function setProxyDir($proxyDir) |
|
421 | { |
||
422 | 56 | $this->proxyDir = $proxyDir; |
|
423 | |||
424 | 56 | return $this; |
|
425 | } |
||
426 | |||
427 | /** |
||
428 | * @return string |
||
429 | */ |
||
430 | 72 | public function getProxyDir() |
|
431 | { |
||
432 | 72 | return $this->proxyDir; |
|
433 | } |
||
434 | |||
435 | /** |
||
436 | * @param string $proxyNamespace |
||
437 | * @return self |
||
438 | */ |
||
439 | 56 | public function setProxyNamespace($proxyNamespace) |
|
440 | { |
||
441 | 56 | $this->proxyNamespace = $proxyNamespace; |
|
442 | |||
443 | 56 | return $this; |
|
444 | } |
||
445 | |||
446 | /** |
||
447 | * @return string |
||
448 | */ |
||
449 | 72 | public function getProxyNamespace() |
|
450 | { |
||
451 | 72 | return $this->proxyNamespace; |
|
452 | } |
||
453 | |||
454 | /** |
||
455 | * @param string $queryCache |
||
456 | * @return self |
||
457 | */ |
||
458 | 56 | public function setQueryCache($queryCache) |
|
459 | { |
||
460 | 56 | $this->queryCache = $queryCache; |
|
461 | |||
462 | 56 | return $this; |
|
463 | } |
||
464 | |||
465 | /** |
||
466 | * @return string |
||
467 | */ |
||
468 | 72 | public function getQueryCache() |
|
469 | { |
||
470 | 72 | return "doctrine.cache.{$this->queryCache}"; |
|
471 | } |
||
472 | |||
473 | /** |
||
474 | * @param array $stringFunctions |
||
475 | * @return self |
||
476 | */ |
||
477 | 56 | public function setStringFunctions($stringFunctions) |
|
478 | { |
||
479 | 56 | $this->stringFunctions = $stringFunctions; |
|
480 | |||
481 | 56 | return $this; |
|
482 | } |
||
483 | |||
484 | /** |
||
485 | * @return array |
||
486 | */ |
||
487 | 72 | public function getStringFunctions() |
|
488 | { |
||
489 | 72 | return $this->stringFunctions; |
|
490 | } |
||
491 | |||
492 | /** |
||
493 | * @param array $modes |
||
494 | * @return self |
||
495 | */ |
||
496 | public function setCustomHydrationModes($modes) |
||
497 | { |
||
498 | $this->customHydrationModes = $modes; |
||
499 | |||
500 | return $this; |
||
501 | } |
||
502 | |||
503 | /** |
||
504 | * @return array |
||
505 | */ |
||
506 | 72 | public function getCustomHydrationModes() |
|
507 | { |
||
508 | 72 | return $this->customHydrationModes; |
|
509 | } |
||
510 | |||
511 | /** |
||
512 | * @param string|null|NamingStrategy $namingStrategy |
||
513 | * @return self |
||
514 | * @throws InvalidArgumentException when the provided naming strategy does not fit the expected type |
||
515 | */ |
||
516 | 4 | public function setNamingStrategy($namingStrategy) |
|
517 | { |
||
518 | 4 | if (null === $namingStrategy |
|
519 | 4 | || is_string($namingStrategy) |
|
520 | 4 | || $namingStrategy instanceof NamingStrategy |
|
521 | 4 | ) { |
|
522 | 4 | $this->namingStrategy = $namingStrategy; |
|
523 | |||
524 | 4 | return $this; |
|
525 | } |
||
526 | |||
527 | 1 | throw new InvalidArgumentException( |
|
528 | 1 | sprintf( |
|
529 | 'namingStrategy must be either a string, a Doctrine\ORM\Mapping\NamingStrategy ' |
||
530 | 1 | . 'instance or null, %s given', |
|
531 | 1 | is_object($namingStrategy) ? get_class($namingStrategy) : gettype($namingStrategy) |
|
532 | 1 | ) |
|
533 | 1 | ); |
|
534 | } |
||
535 | |||
536 | /** |
||
537 | * @return string|null|NamingStrategy |
||
538 | */ |
||
539 | 73 | public function getNamingStrategy() |
|
540 | { |
||
541 | 73 | return $this->namingStrategy; |
|
542 | } |
||
543 | |||
544 | /** |
||
545 | * @param string|null|QuoteStrategy $quoteStrategy |
||
546 | * @return self |
||
547 | * @throws InvalidArgumentException when the provided quote strategy does not fit the expected type |
||
548 | */ |
||
549 | 4 | public function setQuoteStrategy($quoteStrategy) |
|
550 | { |
||
551 | 4 | if (null === $quoteStrategy |
|
552 | 4 | || is_string($quoteStrategy) |
|
553 | 4 | || $quoteStrategy instanceof QuoteStrategy |
|
554 | 4 | ) { |
|
555 | 4 | $this->quoteStrategy = $quoteStrategy; |
|
556 | |||
557 | 4 | return $this; |
|
558 | } |
||
559 | |||
560 | 1 | throw new InvalidArgumentException( |
|
561 | 1 | sprintf( |
|
562 | 'quoteStrategy must be either a string, a Doctrine\ORM\Mapping\QuoteStrategy ' |
||
563 | 1 | . 'instance or null, %s given', |
|
564 | 1 | is_object($quoteStrategy) ? get_class($quoteStrategy) : gettype($quoteStrategy) |
|
565 | 1 | ) |
|
566 | 1 | ); |
|
567 | } |
||
568 | |||
569 | /** |
||
570 | * @return string|null|QuoteStrategy |
||
571 | */ |
||
572 | 72 | public function getQuoteStrategy() |
|
576 | |||
577 | /** |
||
578 | * @param string|null|RepositoryFactory $repositoryFactory |
||
579 | * @return self |
||
580 | * @throws InvalidArgumentException when the provided repository factory does not fit the expected type |
||
581 | */ |
||
582 | 1 | public function setRepositoryFactory($repositoryFactory) |
|
583 | { |
||
584 | 1 | if (null === $repositoryFactory |
|
585 | 1 | || is_string($repositoryFactory) |
|
586 | 1 | || $repositoryFactory instanceof RepositoryFactory |
|
587 | 1 | ) { |
|
588 | 1 | $this->repositoryFactory = $repositoryFactory; |
|
589 | |||
590 | 1 | return $this; |
|
591 | } |
||
592 | |||
593 | 1 | throw new InvalidArgumentException( |
|
594 | 1 | sprintf( |
|
595 | 'repositoryFactory must be either a string, a Doctrine\ORM\Repository\RepositoryFactory ' |
||
596 | 1 | . 'instance or null, %s given', |
|
597 | 1 | is_object($repositoryFactory) ? get_class($repositoryFactory) : gettype($repositoryFactory) |
|
598 | 1 | ) |
|
599 | 1 | ); |
|
600 | } |
||
601 | |||
602 | /** |
||
603 | * @return string|null|RepositoryFactory |
||
604 | */ |
||
605 | 71 | public function getRepositoryFactory() |
|
606 | { |
||
607 | 71 | return $this->repositoryFactory; |
|
608 | } |
||
609 | |||
610 | /** |
||
611 | * Set the metadata factory class name to use |
||
612 | * |
||
613 | * @see \Doctrine\ORM\Configuration::setClassMetadataFactoryName() |
||
614 | * |
||
615 | * @param string $factoryName |
||
616 | */ |
||
617 | 1 | public function setClassMetadataFactoryName($factoryName) |
|
618 | { |
||
619 | 1 | $this->classMetadataFactoryName = (string) $factoryName; |
|
620 | 1 | } |
|
621 | |||
622 | /** |
||
623 | * @return string |
||
624 | */ |
||
625 | 72 | public function getClassMetadataFactoryName() |
|
626 | { |
||
627 | 72 | return $this->classMetadataFactoryName; |
|
628 | } |
||
629 | |||
630 | /** |
||
631 | * @param string|null|EntityListenerResolver $entityListenerResolver |
||
632 | * @return self |
||
633 | * @throws InvalidArgumentException When the provided entity listener resolver |
||
634 | * does not fit the expected type |
||
635 | */ |
||
636 | 3 | public function setEntityListenerResolver($entityListenerResolver) |
|
637 | { |
||
638 | 3 | if (null === $entityListenerResolver |
|
639 | 3 | || $entityListenerResolver instanceof EntityListenerResolver |
|
640 | 3 | || is_string($entityListenerResolver) |
|
641 | 3 | ) { |
|
642 | 3 | $this->entityListenerResolver = $entityListenerResolver; |
|
643 | |||
644 | 3 | return $this; |
|
645 | } |
||
646 | |||
647 | 1 | throw new InvalidArgumentException(sprintf( |
|
648 | 'entityListenerResolver must be either a string, a Doctrine\ORM\Mapping\EntityListenerResolver ' |
||
649 | 1 | . 'instance or null, %s given', |
|
650 | 1 | is_object($entityListenerResolver) ? get_class($entityListenerResolver) : gettype($entityListenerResolver) |
|
651 | 1 | )); |
|
652 | } |
||
653 | |||
654 | /** |
||
655 | * @return string|null|EntityListenerResolver |
||
656 | */ |
||
657 | 71 | public function getEntityListenerResolver() |
|
658 | { |
||
659 | 71 | return $this->entityListenerResolver; |
|
660 | } |
||
661 | |||
662 | /** |
||
663 | * @param array $secondLevelCache |
||
664 | * @return void |
||
665 | */ |
||
666 | 57 | public function setSecondLevelCache(array $secondLevelCache) |
|
670 | |||
671 | /** |
||
672 | * @return SecondLevelCacheConfiguration |
||
673 | */ |
||
674 | 70 | public function getSecondLevelCache() |
|
678 | |||
679 | /** |
||
680 | * Sets default repository class. |
||
681 | * |
||
682 | * @param string $className |
||
683 | * @return void |
||
684 | */ |
||
685 | 57 | public function setDefaultRepositoryClassName($className) |
|
686 | { |
||
687 | 57 | $this->defaultRepositoryClassName = (string) $className; |
|
688 | 57 | } |
|
689 | |||
690 | /** |
||
691 | * Get default repository class name. |
||
692 | * |
||
693 | * @return string|null |
||
694 | */ |
||
695 | 70 | public function getDefaultRepositoryClassName() |
|
696 | { |
||
697 | 70 | return $this->defaultRepositoryClassName; |
|
698 | } |
||
699 | } |
||
700 |