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 |
||
44 | class Configuration extends DBALConfiguration |
||
45 | { |
||
46 | /** |
||
47 | * @var ProxyManagerConfiguration|null |
||
48 | */ |
||
49 | private $proxyManagerConfiguration; |
||
50 | |||
51 | /** |
||
52 | * @var MappingDriver|null |
||
53 | */ |
||
54 | private $metadataDriver; |
||
55 | |||
56 | /** |
||
57 | * @var CacheDriver|null |
||
58 | */ |
||
59 | private $queryCache; |
||
60 | |||
61 | /** |
||
62 | 2296 | * @var CacheDriver|null |
|
63 | */ |
||
64 | 2296 | private $hydrationCache; |
|
65 | 2296 | ||
66 | /** |
||
67 | * @var CacheDriver|null |
||
68 | */ |
||
69 | private $metadataCache; |
||
70 | |||
71 | /** |
||
72 | 2293 | * @var string[] indexed by alias |
|
73 | */ |
||
74 | 2293 | private $entityNamespaces = []; |
|
75 | 2293 | ||
76 | 2293 | /** |
|
77 | * @var string[] of DQL, indexed by query name |
||
78 | */ |
||
79 | private $namedQueries = []; |
||
80 | |||
81 | /** |
||
82 | * @var string[][]|ResultSetMapping[][] tuples of [$sqlString, $resultSetMapping] indexed by query name |
||
83 | */ |
||
84 | 2295 | private $namedNativeQueries = []; |
|
85 | |||
86 | 2295 | /** |
|
87 | 5 | * @var string[][]|ResultSetMapping[][] tuples of [$sqlString, $resultSetMapping] indexed by query name |
|
88 | 2295 | */ |
|
89 | private $customStringFunctions = []; |
||
90 | |||
91 | /** |
||
92 | * @var string[][]|ResultSetMapping[][] tuples of [$sqlString, $resultSetMapping] indexed by query name |
||
93 | */ |
||
94 | private $customNumericFunctions = []; |
||
95 | |||
96 | /** |
||
97 | * @var string[][]|ResultSetMapping[][] tuples of [$sqlString, $resultSetMapping] indexed by query name |
||
98 | */ |
||
99 | 14 | private $customDatetimeFunctions = []; |
|
100 | |||
101 | 14 | /** |
|
102 | 14 | * @var string[] of hydrator class names, indexed by mode name |
|
103 | */ |
||
104 | private $customHydrationModes = []; |
||
105 | |||
106 | /** |
||
107 | * @var string |
||
108 | */ |
||
109 | 2292 | private $classMetadataFactoryClassName = ClassMetadataFactory::class; |
|
110 | |||
111 | 2292 | /** |
|
112 | 2292 | * @var string[] of filter class names, indexed by filter name |
|
113 | 2292 | */ |
|
114 | private $filters; |
||
115 | |||
116 | /** |
||
117 | * @var string |
||
118 | */ |
||
119 | private $defaultRepositoryClassName = EntityRepository::class; |
||
120 | |||
121 | /** |
||
122 | * @var NamingStrategy|null |
||
123 | 2296 | */ |
|
124 | private $namingStrategy; |
||
125 | 2296 | ||
126 | 2296 | /** |
|
127 | * @var EntityListenerResolver|null |
||
128 | */ |
||
129 | private $entityListenerResolver; |
||
130 | |||
131 | /** |
||
132 | * @var RepositoryFactory|null |
||
133 | */ |
||
134 | private $repositoryFactory; |
||
135 | |||
136 | /** |
||
137 | * @var bool |
||
138 | 2295 | */ |
|
139 | private $isSecondLevelCacheEnabled = false; |
||
140 | 2295 | ||
141 | 2295 | /** |
|
142 | * @var CacheConfiguration|null |
||
143 | */ |
||
144 | private $secondLevelCacheConfiguration; |
||
145 | |||
146 | /** |
||
147 | * @var mixed[] indexed by hint name |
||
148 | */ |
||
149 | private $defaultQueryHints = []; |
||
150 | |||
151 | /** |
||
152 | 2275 | * Sets the directory where Doctrine generates any necessary proxy class files. |
|
153 | */ |
||
154 | 2275 | public function setProxyDir(string $directory) : void |
|
159 | 2275 | ||
160 | 2275 | /** |
|
161 | * Sets the strategy for automatically generating proxy classes. |
||
162 | 2275 | * |
|
163 | * @param boolean|int $autoGenerate Possible values are constants of Doctrine\ORM\Proxy\Factory\ProxyFactory. |
||
164 | * True is converted to AUTOGENERATE_ALWAYS, false to AUTOGENERATE_NEVER. |
||
165 | 1 | */ |
|
166 | 1 | public function setAutoGenerateProxyClasses($autoGenerate) : void |
|
186 | |||
187 | /** |
||
188 | * Sets the namespace where proxy classes reside. |
||
189 | */ |
||
190 | public function setProxyNamespace(string $namespace) : void |
||
194 | |||
195 | 13 | /** |
|
196 | 1 | * Sets the cache driver implementation that is used for metadata caching. |
|
197 | * |
||
198 | * @todo Force parameter to be a Closure to ensure lazy evaluation |
||
199 | 13 | * (as soon as a metadata cache is in effect, the driver never needs to initialize). |
|
200 | */ |
||
201 | public function setMetadataDriverImpl(MappingDriver $metadataDriver) : void |
||
205 | |||
206 | /** |
||
207 | * Adds a new default annotation driver with a correctly configured annotation reader. |
||
208 | * |
||
209 | 92 | * @param string[] $paths |
|
210 | * |
||
211 | 92 | * @return AnnotationDriver |
|
212 | 92 | */ |
|
213 | public function newDefaultAnnotationDriver(array $paths = []) : AnnotationDriver |
||
221 | 1 | ||
222 | /** |
||
223 | * Gets the cache driver implementation that is used for the mapping metadata. |
||
224 | */ |
||
225 | public function getMetadataDriverImpl() : ?MappingDriver |
||
229 | |||
230 | /** |
||
231 | 1447 | * Gets the cache driver implementation that is used for the query cache (SQL cache). |
|
232 | */ |
||
233 | 1447 | public function getQueryCacheImpl() : ?CacheDriver |
|
237 | |||
238 | /** |
||
239 | * Sets the cache driver implementation that is used for the query cache (SQL cache). |
||
240 | */ |
||
241 | public function setQueryCacheImpl(CacheDriver $queryCache) : void |
||
245 | 568 | ||
246 | 567 | /** |
|
247 | 568 | * Gets the cache driver implementation that is used for the hydration cache (SQL cache). |
|
248 | */ |
||
249 | public function getHydrationCacheImpl() : ?CacheDriver |
||
253 | |||
254 | /** |
||
255 | * Sets the cache driver implementation that is used for the hydration cache (SQL cache). |
||
256 | */ |
||
257 | 2242 | public function setHydrationCacheImpl(CacheDriver $hydrationCache) : void |
|
261 | |||
262 | /** |
||
263 | * Gets the cache driver implementation that is used for metadata caching. |
||
264 | */ |
||
265 | public function getMetadataCacheImpl() : ?CacheDriver |
||
269 | 1 | ||
270 | 1 | /** |
|
271 | 1 | * Sets the cache driver implementation that is used for metadata caching. |
|
272 | */ |
||
273 | public function setMetadataCacheImpl(CacheDriver $metadataCache) : void |
||
277 | |||
278 | /** |
||
279 | * Adds a named DQL query to the configuration. |
||
280 | */ |
||
281 | 1 | public function addNamedQuery(string $queryName, string $dqlQuery) : void |
|
285 | |||
286 | /** |
||
287 | * Gets a previously registered named DQL query. |
||
288 | * |
||
289 | * @throws ORMException |
||
290 | */ |
||
291 | 2299 | public function getNamedQuery(string $queryName) : string |
|
299 | |||
300 | /** |
||
301 | * Adds a named native query to the configuration. |
||
302 | */ |
||
303 | public function addNamedNativeQuery(string $queryName, string $sql, ResultSetMapping $resultSetMapping) : void |
||
307 | 2242 | ||
308 | 2242 | /** |
|
309 | * Gets the components of a previously registered named native query. |
||
310 | * |
||
311 | * @return string[]|ResultSetMapping[] tuple of [$sqlString, $resultSetMaping] |
||
312 | * |
||
313 | * @throws ORMException |
||
314 | */ |
||
315 | public function getNamedNativeQuery(string $queryName) : array |
||
323 | |||
324 | /** |
||
325 | * Ensures that this Configuration instance contains settings that are |
||
326 | * suitable for a production environment. |
||
327 | * |
||
328 | * @throws ORMException If a configuration setting has a value that is not |
||
329 | * suitable for a production environment. |
||
330 | */ |
||
331 | public function ensureProductionSettings() : void |
||
357 | |||
358 | /** |
||
359 | * Registers a custom DQL function that produces a string value. |
||
360 | * Such a function can then be used in any DQL statement in any place where string |
||
361 | * functions are allowed. |
||
362 | * |
||
363 | * DQL function names are case-insensitive. |
||
364 | * |
||
365 | 1 | * @param string|callable $classNameOrFactory Class name or a callable that returns the function. |
|
366 | */ |
||
367 | 1 | public function addCustomStringFunction(string $functionName, $classNameOrFactory) : void |
|
371 | 1 | ||
372 | /** |
||
373 | * Gets the implementation class name of a registered custom string DQL function. |
||
374 | * |
||
375 | * @return string|callable|null |
||
376 | */ |
||
377 | public function getCustomStringFunction(string $functionName) |
||
381 | |||
382 | /** |
||
383 | 8 | * Sets a map of custom DQL string functions. |
|
384 | * |
||
385 | 8 | * Keys must be function names and values the FQCN of the implementing class. |
|
386 | * The function names will be case-insensitive in DQL. |
||
387 | 8 | * |
|
388 | 1 | * Any previously added string functions are discarded. |
|
389 | * |
||
390 | * @param array $functions The map of custom DQL string functions. |
||
391 | 7 | */ |
|
392 | 1 | public function setCustomStringFunctions(array $functions) : void |
|
398 | 1 | ||
399 | /** |
||
400 | * Registers a custom DQL function that produces a numeric value. |
||
401 | 5 | * Such a function can then be used in any DQL statement in any place where numeric |
|
402 | 1 | * functions are allowed. |
|
403 | * |
||
404 | * DQL function names are case-insensitive. |
||
405 | 4 | * |
|
406 | 3 | * @param string|callable $classNameOrFactory Class name or a callable that returns the function. |
|
407 | */ |
||
408 | 1 | public function addCustomNumericFunction(string $functionName, $classNameOrFactory) : void |
|
412 | |||
413 | /** |
||
414 | * Gets the implementation class name of a registered custom numeric DQL function. |
||
415 | * |
||
416 | * @return string|callable|null |
||
417 | */ |
||
418 | public function getCustomNumericFunction(string $functionName) |
||
422 | |||
423 | /** |
||
424 | 3 | * Sets a map of custom DQL numeric functions. |
|
425 | * |
||
426 | 3 | * Keys must be function names and values the FQCN of the implementing class. |
|
427 | 1 | * The function names will be case-insensitive in DQL. |
|
428 | * |
||
429 | * Any previously added numeric functions are discarded. |
||
430 | 3 | * |
|
431 | 3 | * @param array $functions The map of custom DQL numeric functions. |
|
432 | */ |
||
433 | public function setCustomNumericFunctions(array $functions) : void |
||
439 | |||
440 | 4 | /** |
|
441 | * Registers a custom DQL function that produces a date/time value. |
||
442 | 4 | * Such a function can then be used in any DQL statement in any place where date/time |
|
443 | * functions are allowed. |
||
444 | 4 | * |
|
445 | 3 | * DQL function names are case-insensitive. |
|
446 | 4 | * |
|
447 | * @param string|callable $classNameOrFactory Class name or a callable that returns the function. |
||
448 | */ |
||
449 | public function addCustomDatetimeFunction(string $functionName, $classNameOrFactory) |
||
453 | |||
454 | /** |
||
455 | * Gets the implementation class name of a registered custom date/time DQL function. |
||
456 | * |
||
457 | * @return string|callable|null |
||
458 | */ |
||
459 | public function getCustomDatetimeFunction(string $functionName) |
||
463 | 1 | ||
464 | 1 | /** |
|
465 | * Sets a map of custom DQL date/time functions. |
||
466 | 1 | * |
|
467 | * Keys must be function names and values the FQCN of the implementing class. |
||
468 | * The function names will be case-insensitive in DQL. |
||
469 | * |
||
470 | * Any previously added date/time functions are discarded. |
||
471 | * |
||
472 | * @param array $functions The map of custom DQL date/time functions. |
||
473 | */ |
||
474 | public function setCustomDatetimeFunctions(array $functions) : void |
||
480 | |||
481 | /** |
||
482 | 3 | * Sets the custom hydrator modes in one pass. |
|
483 | * |
||
484 | 3 | * @param iterable $modes An iterable of string $modeName => string $hydratorClassName |
|
485 | 1 | */ |
|
486 | public function setCustomHydrationModes(iterable $modes) : void |
||
494 | |||
495 | /** |
||
496 | * Gets the hydrator class for the given hydration mode name. |
||
497 | * |
||
498 | 3 | * @return string|null The hydrator class name. |
|
499 | */ |
||
500 | 3 | public function getCustomHydrationMode(string $modeName) : ?string |
|
504 | 3 | ||
505 | /** |
||
506 | * Adds a custom hydration mode. |
||
507 | */ |
||
508 | public function addCustomHydrationMode(string $modeName, string $hydratorClassName) : void |
||
512 | |||
513 | /** |
||
514 | * Sets a class metadata factory. |
||
515 | */ |
||
516 | public function setClassMetadataFactoryName(string $classMetadataFactoryClassName) : void |
||
520 | |||
521 | 1 | public function getClassMetadataFactoryName() : string |
|
525 | |||
526 | /** |
||
527 | * Adds a filter to the list of possible filters. |
||
528 | */ |
||
529 | public function addFilter(string $filterName, string $filterClassName) : void |
||
533 | |||
534 | /** |
||
535 | * Gets the class name for a given filter name. |
||
536 | * |
||
537 | * @return string|null The class name of the filter |
||
538 | */ |
||
539 | public function getFilterClassName(string $filterName) : ?string |
||
543 | 1 | ||
544 | /** |
||
545 | * Sets default repository class. |
||
546 | 1 | * |
|
547 | 1 | * @since 2.2 |
|
548 | * |
||
549 | * @throws ORMException If not is a \Doctrine\Common\Persistence\ObjectRepository implementation |
||
550 | */ |
||
551 | public function setDefaultRepositoryClassName(string $repositoryClassName) : void |
||
561 | 1 | ||
562 | 1 | /** |
|
563 | * Get default repository class. |
||
564 | * |
||
565 | * @since 2.2 |
||
566 | */ |
||
567 | public function getDefaultRepositoryClassName() : string |
||
571 | |||
572 | /** |
||
573 | * Sets naming strategy. |
||
574 | * |
||
575 | * @since 2.3 |
||
576 | */ |
||
577 | 1 | public function setNamingStrategy(NamingStrategy $namingStrategy) : void |
|
581 | |||
582 | 1 | /** |
|
583 | * Gets naming strategy.. |
||
584 | * |
||
585 | * @since 2.3 |
||
586 | */ |
||
587 | public function getNamingStrategy() : ?NamingStrategy |
||
592 | |||
593 | 1 | /** |
|
594 | * Set the entity listener resolver. |
||
595 | 1 | * |
|
596 | 1 | * @since 2.4 |
|
597 | */ |
||
598 | 1 | public function setEntityListenerResolver(EntityListenerResolver $resolver) : void |
|
602 | |||
603 | /** |
||
604 | * Get the entity listener resolver. |
||
605 | * |
||
606 | * @since 2.4 |
||
607 | 3 | */ |
|
608 | public function getEntityListenerResolver() : EntityListenerResolver |
||
613 | |||
614 | /** |
||
615 | * Set the entity repository factory. |
||
616 | * |
||
617 | * @since 2.4 |
||
618 | */ |
||
619 | public function setRepositoryFactory(RepositoryFactory $repositoryFactory) : void |
||
623 | |||
624 | 3 | /** |
|
625 | 3 | * Get the entity repository factory. |
|
626 | * |
||
627 | * @since 2.4 |
||
628 | */ |
||
629 | public function getRepositoryFactory() : RepositoryFactory |
||
634 | 1 | ||
635 | /** |
||
636 | 1 | * @since 2.5 |
|
637 | 1 | */ |
|
638 | public function isSecondLevelCacheEnabled() : bool |
||
642 | 2291 | ||
643 | /** |
||
644 | 2291 | * @since 2.5 |
|
645 | 2291 | */ |
|
646 | public function setSecondLevelCacheEnabled(bool $flag = true) : void |
||
650 | |||
651 | /** |
||
652 | * @since 2.5 |
||
653 | */ |
||
654 | public function setSecondLevelCacheConfiguration(CacheConfiguration $cacheConfig) : void |
||
658 | |||
659 | 46 | /** |
|
660 | 46 | * @since 2.5 |
|
661 | * |
||
662 | * @return \Doctrine\ORM\Cache\CacheConfiguration|null |
||
663 | */ |
||
664 | public function getSecondLevelCacheConfiguration() : ?CacheConfiguration |
||
672 | 45 | ||
673 | 45 | /** |
|
674 | 45 | * Returns query hints, which will be applied to every query in application |
|
675 | * |
||
676 | * @since 2.5 |
||
677 | */ |
||
678 | public function getDefaultQueryHints() : array |
||
682 | |||
683 | /** |
||
684 | * Sets array of query hints, which will be applied to every query in application |
||
685 | * |
||
686 | * @since 2.5 |
||
687 | */ |
||
688 | 3 | public function setDefaultQueryHints(array $defaultQueryHints) : void |
|
692 | 3 | ||
693 | 1 | /** |
|
694 | * Gets the value of a default query hint. If the hint name is not recognized, FALSE is returned. |
||
695 | * |
||
696 | 2 | * @since 2.5 |
|
697 | 2 | * |
|
698 | * @return mixed The value of the hint or FALSE, if the hint name is not recognized. |
||
699 | */ |
||
700 | public function getDefaultQueryHint(string $hintName) |
||
704 | |||
705 | /** |
||
706 | 139 | * Sets a default query hint. If the hint name is not recognized, it is silently ignored. |
|
707 | * |
||
708 | 139 | * @since 2.5 |
|
709 | 2 | * |
|
710 | 139 | * @param mixed $value The value of the hint. |
|
711 | */ |
||
712 | public function setDefaultQueryHint(string $hintName, $value) : void |
||
716 | |||
717 | public function buildGhostObjectFactory() : LazyLoadingGhostFactory |
||
721 | |||
722 | 5 | public function getProxyManagerConfiguration() : ProxyManagerConfiguration |
|
727 | } |
||
728 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.