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 |
||
53 | class Configuration extends \Doctrine\DBAL\Configuration |
||
54 | { |
||
55 | /** |
||
56 | * Sets the directory where Doctrine generates any necessary proxy class files. |
||
57 | * |
||
58 | * @param string $dir |
||
59 | * |
||
60 | * @return void |
||
61 | */ |
||
62 | 2354 | public function setProxyDir($dir) |
|
66 | |||
67 | /** |
||
68 | * Gets the directory where Doctrine generates any necessary proxy class files. |
||
69 | * |
||
70 | * @return string|null |
||
71 | */ |
||
72 | 2350 | public function getProxyDir() |
|
78 | |||
79 | /** |
||
80 | * Gets the strategy for automatically generating proxy classes. |
||
81 | * |
||
82 | * @return int Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory. |
||
83 | */ |
||
84 | 2352 | public function getAutoGenerateProxyClasses() |
|
90 | |||
91 | /** |
||
92 | * Sets the strategy for automatically generating proxy classes. |
||
93 | * |
||
94 | * @param boolean|int $autoGenerate Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory. |
||
95 | * True is converted to AUTOGENERATE_ALWAYS, false to AUTOGENERATE_NEVER. |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | 15 | public function setAutoGenerateProxyClasses($autoGenerate) |
|
103 | |||
104 | /** |
||
105 | * Gets the namespace where proxy classes reside. |
||
106 | * |
||
107 | * @return string|null |
||
108 | */ |
||
109 | 2349 | public function getProxyNamespace() |
|
115 | |||
116 | /** |
||
117 | * Sets the namespace where proxy classes reside. |
||
118 | * |
||
119 | * @param string $ns |
||
120 | * |
||
121 | * @return void |
||
122 | */ |
||
123 | 2354 | public function setProxyNamespace($ns) |
|
127 | |||
128 | /** |
||
129 | * Returns the umask that controls file permissions for generated proxies. |
||
130 | * |
||
131 | * @return int |
||
132 | */ |
||
133 | 2348 | public function getProxyUmask() |
|
138 | |||
139 | /** |
||
140 | * @since 2.5.6 |
||
141 | * |
||
142 | * @param int $umask The umask that controls file permissions for generated proxies. |
||
143 | * |
||
144 | * @throws ORMException |
||
145 | */ |
||
146 | 1 | public function setProxyUmask($umask) |
|
154 | |||
155 | /** |
||
156 | * Sets the cache driver implementation that is used for metadata caching. |
||
157 | * |
||
158 | * @param MappingDriver $driverImpl |
||
159 | * |
||
160 | * @return void |
||
161 | * |
||
162 | * @todo Force parameter to be a Closure to ensure lazy evaluation |
||
163 | * (as soon as a metadata cache is in effect, the driver never needs to initialize). |
||
164 | */ |
||
165 | 2353 | public function setMetadataDriverImpl(MappingDriver $driverImpl) |
|
169 | |||
170 | /** |
||
171 | * Adds a new default annotation driver with a correctly configured annotation reader. If $useSimpleAnnotationReader |
||
172 | * is true, the notation `@Entity` will work, otherwise, the notation `@ORM\Entity` will be supported. |
||
173 | * |
||
174 | * @param array $paths |
||
175 | * @param bool $useSimpleAnnotationReader |
||
176 | * |
||
177 | * @return AnnotationDriver |
||
178 | */ |
||
179 | 2329 | public function newDefaultAnnotationDriver($paths = array(), $useSimpleAnnotationReader = true) |
|
197 | |||
198 | /** |
||
199 | * Adds a namespace under a certain alias. |
||
200 | * |
||
201 | * @param string $alias |
||
202 | * @param string $namespace |
||
203 | * |
||
204 | * @return void |
||
205 | */ |
||
206 | 8 | public function addEntityNamespace($alias, $namespace) |
|
210 | |||
211 | /** |
||
212 | * Resolves a registered namespace alias to the full namespace. |
||
213 | * |
||
214 | * @param string $entityNamespaceAlias |
||
215 | * |
||
216 | * @return string |
||
217 | * |
||
218 | * @throws ORMException |
||
219 | */ |
||
220 | 13 | public function getEntityNamespace($entityNamespaceAlias) |
|
228 | |||
229 | /** |
||
230 | * Sets the entity alias map. |
||
231 | * |
||
232 | * @param array $entityNamespaces |
||
233 | * |
||
234 | * @return void |
||
235 | */ |
||
236 | 95 | public function setEntityNamespaces(array $entityNamespaces) |
|
240 | |||
241 | /** |
||
242 | * Retrieves the list of registered entity namespace aliases. |
||
243 | * |
||
244 | * @return array |
||
245 | */ |
||
246 | 1 | public function getEntityNamespaces() |
|
250 | |||
251 | /** |
||
252 | * Gets the cache driver implementation that is used for the mapping metadata. |
||
253 | * |
||
254 | * @return MappingDriver|null |
||
255 | * |
||
256 | * @throws ORMException |
||
257 | */ |
||
258 | 1489 | public function getMetadataDriverImpl() |
|
264 | |||
265 | /** |
||
266 | * Gets the cache driver implementation that is used for the query cache (SQL cache). |
||
267 | * |
||
268 | * @return \Doctrine\Common\Cache\Cache|null |
||
269 | */ |
||
270 | 569 | public function getQueryCacheImpl() |
|
276 | |||
277 | /** |
||
278 | * Sets the cache driver implementation that is used for the query cache (SQL cache). |
||
279 | * |
||
280 | * @param \Doctrine\Common\Cache\Cache $cacheImpl |
||
281 | * |
||
282 | * @return void |
||
283 | */ |
||
284 | 2295 | public function setQueryCacheImpl(CacheDriver $cacheImpl) |
|
288 | |||
289 | /** |
||
290 | * Gets the cache driver implementation that is used for the hydration cache (SQL cache). |
||
291 | * |
||
292 | * @return \Doctrine\Common\Cache\Cache|null |
||
293 | */ |
||
294 | 1 | public function getHydrationCacheImpl() |
|
300 | |||
301 | /** |
||
302 | * Sets the cache driver implementation that is used for the hydration cache (SQL cache). |
||
303 | * |
||
304 | * @param \Doctrine\Common\Cache\Cache $cacheImpl |
||
305 | * |
||
306 | * @return void |
||
307 | */ |
||
308 | 1 | public function setHydrationCacheImpl(CacheDriver $cacheImpl) |
|
312 | |||
313 | /** |
||
314 | * Gets the cache driver implementation that is used for metadata caching. |
||
315 | * |
||
316 | * @return \Doctrine\Common\Cache\Cache|null |
||
317 | */ |
||
318 | 2356 | public function getMetadataCacheImpl() |
|
324 | |||
325 | /** |
||
326 | * Sets the cache driver implementation that is used for metadata caching. |
||
327 | * |
||
328 | * @param \Doctrine\Common\Cache\Cache $cacheImpl |
||
329 | * |
||
330 | * @return void |
||
331 | */ |
||
332 | 2295 | public function setMetadataCacheImpl(CacheDriver $cacheImpl) |
|
336 | |||
337 | /** |
||
338 | * Adds a named DQL query to the configuration. |
||
339 | * |
||
340 | * @param string $name The name of the query. |
||
341 | * @param string $dql The DQL query string. |
||
342 | * |
||
343 | * @return void |
||
344 | */ |
||
345 | 1 | public function addNamedQuery($name, $dql) |
|
349 | |||
350 | /** |
||
351 | * Gets a previously registered named DQL query. |
||
352 | * |
||
353 | * @param string $name The name of the query. |
||
354 | * |
||
355 | * @return string The DQL query. |
||
356 | * |
||
357 | * @throws ORMException |
||
358 | */ |
||
359 | 2 | public function getNamedQuery($name) |
|
367 | |||
368 | /** |
||
369 | * Adds a named native query to the configuration. |
||
370 | * |
||
371 | * @param string $name The name of the query. |
||
372 | * @param string $sql The native SQL query string. |
||
373 | * @param Query\ResultSetMapping $rsm The ResultSetMapping used for the results of the SQL query. |
||
374 | * |
||
375 | * @return void |
||
376 | */ |
||
377 | 1 | public function addNamedNativeQuery($name, $sql, Query\ResultSetMapping $rsm) |
|
381 | |||
382 | /** |
||
383 | * Gets the components of a previously registered named native query. |
||
384 | * |
||
385 | * @param string $name The name of the query. |
||
386 | * |
||
387 | * @return array A tuple with the first element being the SQL string and the second |
||
388 | * element being the ResultSetMapping. |
||
389 | * |
||
390 | * @throws ORMException |
||
391 | */ |
||
392 | 1 | public function getNamedNativeQuery($name) |
|
400 | |||
401 | /** |
||
402 | * Ensures that this Configuration instance contains settings that are |
||
403 | * suitable for a production environment. |
||
404 | * |
||
405 | * @return void |
||
406 | * |
||
407 | * @throws ORMException If a configuration setting has a value that is not |
||
408 | * suitable for a production environment. |
||
409 | */ |
||
410 | 8 | public function ensureProductionSettings() |
|
436 | |||
437 | /** |
||
438 | * Registers a custom DQL function that produces a string value. |
||
439 | * Such a function can then be used in any DQL statement in any place where string |
||
440 | * functions are allowed. |
||
441 | * |
||
442 | * DQL function names are case-insensitive. |
||
443 | * |
||
444 | * @param string $name Function name. |
||
445 | * @param string|callable $className Class name or a callable that returns the function. |
||
446 | * |
||
447 | * @return void |
||
448 | * |
||
449 | * @throws ORMException |
||
450 | */ |
||
451 | 3 | public function addCustomStringFunction($name, $className) |
|
459 | |||
460 | /** |
||
461 | * Gets the implementation class name of a registered custom string DQL function. |
||
462 | * |
||
463 | * @param string $name |
||
464 | * |
||
465 | * @return string|null |
||
466 | */ |
||
467 | 4 | public function getCustomStringFunction($name) |
|
475 | |||
476 | /** |
||
477 | * Sets a map of custom DQL string functions. |
||
478 | * |
||
479 | * Keys must be function names and values the FQCN of the implementing class. |
||
480 | * The function names will be case-insensitive in DQL. |
||
481 | * |
||
482 | * Any previously added string functions are discarded. |
||
483 | * |
||
484 | * @param array $functions The map of custom DQL string functions. |
||
485 | * |
||
486 | * @return void |
||
487 | */ |
||
488 | 1 | public function setCustomStringFunctions(array $functions) |
|
494 | |||
495 | /** |
||
496 | * Registers a custom DQL function that produces a numeric value. |
||
497 | * Such a function can then be used in any DQL statement in any place where numeric |
||
498 | * functions are allowed. |
||
499 | * |
||
500 | * DQL function names are case-insensitive. |
||
501 | * |
||
502 | * @param string $name Function name. |
||
503 | * @param string|callable $className Class name or a callable that returns the function. |
||
504 | * |
||
505 | * @return void |
||
506 | * |
||
507 | * @throws ORMException |
||
508 | */ |
||
509 | 3 | public function addCustomNumericFunction($name, $className) |
|
517 | |||
518 | /** |
||
519 | * Gets the implementation class name of a registered custom numeric DQL function. |
||
520 | * |
||
521 | * @param string $name |
||
522 | * |
||
523 | * @return string|null |
||
524 | */ |
||
525 | 3 | public function getCustomNumericFunction($name) |
|
533 | |||
534 | /** |
||
535 | * Sets a map of custom DQL numeric functions. |
||
536 | * |
||
537 | * Keys must be function names and values the FQCN of the implementing class. |
||
538 | * The function names will be case-insensitive in DQL. |
||
539 | * |
||
540 | * Any previously added numeric functions are discarded. |
||
541 | * |
||
542 | * @param array $functions The map of custom DQL numeric functions. |
||
543 | * |
||
544 | * @return void |
||
545 | */ |
||
546 | 2 | public function setCustomNumericFunctions(array $functions) |
|
552 | |||
553 | /** |
||
554 | * Registers a custom DQL function that produces a date/time value. |
||
555 | * Such a function can then be used in any DQL statement in any place where date/time |
||
556 | * functions are allowed. |
||
557 | * |
||
558 | * DQL function names are case-insensitive. |
||
559 | * |
||
560 | * @param string $name Function name. |
||
561 | * @param string|callable $className Class name or a callable that returns the function. |
||
562 | * |
||
563 | * @return void |
||
564 | * |
||
565 | * @throws ORMException |
||
566 | */ |
||
567 | 1 | public function addCustomDatetimeFunction($name, $className) |
|
575 | |||
576 | /** |
||
577 | * Gets the implementation class name of a registered custom date/time DQL function. |
||
578 | * |
||
579 | * @param string $name |
||
580 | * |
||
581 | * @return string|null |
||
582 | */ |
||
583 | 1 | public function getCustomDatetimeFunction($name) |
|
591 | |||
592 | /** |
||
593 | * Sets a map of custom DQL date/time functions. |
||
594 | * |
||
595 | * Keys must be function names and values the FQCN of the implementing class. |
||
596 | * The function names will be case-insensitive in DQL. |
||
597 | * |
||
598 | * Any previously added date/time functions are discarded. |
||
599 | * |
||
600 | * @param array $functions The map of custom DQL date/time functions. |
||
601 | * |
||
602 | * @return void |
||
603 | */ |
||
604 | 1 | public function setCustomDatetimeFunctions(array $functions) |
|
610 | |||
611 | /** |
||
612 | * Sets the custom hydrator modes in one pass. |
||
613 | * |
||
614 | * @param array $modes An array of ($modeName => $hydrator). |
||
615 | * |
||
616 | * @return void |
||
617 | */ |
||
618 | 1 | public function setCustomHydrationModes($modes) |
|
626 | |||
627 | /** |
||
628 | * Gets the hydrator class for the given hydration mode name. |
||
629 | * |
||
630 | * @param string $modeName The hydration mode name. |
||
631 | * |
||
632 | * @return string|null The hydrator class name. |
||
633 | */ |
||
634 | 3 | public function getCustomHydrationMode($modeName) |
|
640 | |||
641 | /** |
||
642 | * Adds a custom hydration mode. |
||
643 | * |
||
644 | * @param string $modeName The hydration mode name. |
||
645 | * @param string $hydrator The hydrator class name. |
||
646 | * |
||
647 | * @return void |
||
648 | */ |
||
649 | 3 | public function addCustomHydrationMode($modeName, $hydrator) |
|
653 | |||
654 | /** |
||
655 | * Sets a class metadata factory. |
||
656 | * |
||
657 | * @param string $cmfName |
||
658 | * |
||
659 | * @return void |
||
660 | */ |
||
661 | 1 | public function setClassMetadataFactoryName($cmfName) |
|
665 | |||
666 | /** |
||
667 | * @return string |
||
668 | */ |
||
669 | 2348 | public function getClassMetadataFactoryName() |
|
677 | |||
678 | /** |
||
679 | * Adds a filter to the list of possible filters. |
||
680 | * |
||
681 | * @param string $name The name of the filter. |
||
682 | * @param string $className The class name of the filter. |
||
683 | */ |
||
684 | 46 | public function addFilter($name, $className) |
|
688 | |||
689 | /** |
||
690 | * Gets the class name for a given filter name. |
||
691 | * |
||
692 | * @param string $name The name of the filter. |
||
693 | * |
||
694 | * @return string The class name of the filter, or null if it is not |
||
695 | * defined. |
||
696 | */ |
||
697 | 45 | public function getFilterClassName($name) |
|
703 | |||
704 | /** |
||
705 | * Sets default repository class. |
||
706 | * |
||
707 | * @since 2.2 |
||
708 | * |
||
709 | * @param string $className |
||
710 | * |
||
711 | * @return void |
||
712 | * |
||
713 | * @throws ORMException If not is a \Doctrine\Common\Persistence\ObjectRepository |
||
714 | */ |
||
715 | 3 | public function setDefaultRepositoryClassName($className) |
|
725 | |||
726 | /** |
||
727 | * Get default repository class. |
||
728 | * |
||
729 | * @since 2.2 |
||
730 | * |
||
731 | * @return string |
||
732 | */ |
||
733 | 142 | public function getDefaultRepositoryClassName() |
|
739 | |||
740 | /** |
||
741 | * Sets naming strategy. |
||
742 | * |
||
743 | * @since 2.3 |
||
744 | * |
||
745 | * @param NamingStrategy $namingStrategy |
||
746 | * |
||
747 | * @return void |
||
748 | */ |
||
749 | 7 | public function setNamingStrategy(NamingStrategy $namingStrategy) |
|
753 | |||
754 | /** |
||
755 | * Gets naming strategy.. |
||
756 | * |
||
757 | * @since 2.3 |
||
758 | * |
||
759 | * @return NamingStrategy |
||
760 | */ |
||
761 | 428 | public function getNamingStrategy() |
|
769 | |||
770 | /** |
||
771 | * Sets quote strategy. |
||
772 | * |
||
773 | * @since 2.3 |
||
774 | * |
||
775 | * @param \Doctrine\ORM\Mapping\QuoteStrategy $quoteStrategy |
||
776 | * |
||
777 | * @return void |
||
778 | */ |
||
779 | 2 | public function setQuoteStrategy(QuoteStrategy $quoteStrategy) |
|
783 | |||
784 | /** |
||
785 | * Gets quote strategy. |
||
786 | * |
||
787 | * @since 2.3 |
||
788 | * |
||
789 | * @return \Doctrine\ORM\Mapping\QuoteStrategy |
||
790 | */ |
||
791 | 1615 | public function getQuoteStrategy() |
|
799 | |||
800 | /** |
||
801 | * Set the entity listener resolver. |
||
802 | * |
||
803 | * @since 2.4 |
||
804 | * @param \Doctrine\ORM\Mapping\EntityListenerResolver $resolver |
||
805 | */ |
||
806 | 1 | public function setEntityListenerResolver(EntityListenerResolver $resolver) |
|
810 | |||
811 | /** |
||
812 | * Get the entity listener resolver. |
||
813 | * |
||
814 | * @since 2.4 |
||
815 | * @return \Doctrine\ORM\Mapping\EntityListenerResolver |
||
816 | */ |
||
817 | 2348 | public function getEntityListenerResolver() |
|
825 | |||
826 | /** |
||
827 | * Set the entity repository factory. |
||
828 | * |
||
829 | * @since 2.4 |
||
830 | * @param \Doctrine\ORM\Repository\RepositoryFactory $repositoryFactory |
||
831 | */ |
||
832 | public function setRepositoryFactory(RepositoryFactory $repositoryFactory) |
||
836 | |||
837 | /** |
||
838 | * Get the entity repository factory. |
||
839 | * |
||
840 | * @since 2.4 |
||
841 | * @return \Doctrine\ORM\Repository\RepositoryFactory |
||
842 | */ |
||
843 | 2347 | public function getRepositoryFactory() |
|
849 | |||
850 | /** |
||
851 | * @since 2.5 |
||
852 | * |
||
853 | * @return boolean |
||
854 | */ |
||
855 | 2348 | public function isSecondLevelCacheEnabled() |
|
861 | |||
862 | /** |
||
863 | * @since 2.5 |
||
864 | * |
||
865 | * @param boolean $flag |
||
866 | * |
||
867 | * @return void |
||
868 | */ |
||
869 | 278 | public function setSecondLevelCacheEnabled($flag = true) |
|
873 | |||
874 | /** |
||
875 | * @since 2.5 |
||
876 | * |
||
877 | * @param \Doctrine\ORM\Cache\CacheConfiguration $cacheConfig |
||
878 | * |
||
879 | * @return void |
||
880 | */ |
||
881 | 279 | public function setSecondLevelCacheConfiguration(CacheConfiguration $cacheConfig) |
|
885 | |||
886 | /** |
||
887 | * @since 2.5 |
||
888 | * |
||
889 | * @return \Doctrine\ORM\Cache\CacheConfiguration|null |
||
890 | */ |
||
891 | 279 | public function getSecondLevelCacheConfiguration() |
|
901 | |||
902 | /** |
||
903 | * Returns query hints, which will be applied to every query in application |
||
904 | * |
||
905 | * @since 2.5 |
||
906 | * |
||
907 | * @return array |
||
908 | */ |
||
909 | 946 | public function getDefaultQueryHints() |
|
913 | |||
914 | /** |
||
915 | * Sets array of query hints, which will be applied to every query in application |
||
916 | * |
||
917 | * @since 2.5 |
||
918 | * |
||
919 | * @param array $defaultQueryHints |
||
920 | */ |
||
921 | 1 | public function setDefaultQueryHints(array $defaultQueryHints) |
|
925 | |||
926 | /** |
||
927 | * Gets the value of a default query hint. If the hint name is not recognized, FALSE is returned. |
||
928 | * |
||
929 | * @since 2.5 |
||
930 | * |
||
931 | * @param string $name The name of the hint. |
||
932 | * |
||
933 | * @return mixed The value of the hint or FALSE, if the hint name is not recognized. |
||
934 | */ |
||
935 | public function getDefaultQueryHint($name) |
||
941 | |||
942 | /** |
||
943 | * Sets a default query hint. If the hint name is not recognized, it is silently ignored. |
||
944 | * |
||
945 | * @since 2.5 |
||
946 | * |
||
947 | * @param string $name The name of the hint. |
||
948 | * @param mixed $value The value of the hint. |
||
949 | */ |
||
950 | 1 | public function setDefaultQueryHint($name, $value) |
|
954 | } |
||
955 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: