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 |
||
55 | class Configuration extends \Doctrine\DBAL\Configuration |
||
56 | { |
||
57 | /** |
||
58 | * Sets the directory where Doctrine generates any necessary proxy class files. |
||
59 | * |
||
60 | * @param string $dir |
||
61 | * |
||
62 | * @return void |
||
63 | */ |
||
64 | 2391 | public function setProxyDir($dir) |
|
68 | |||
69 | /** |
||
70 | * Gets the directory where Doctrine generates any necessary proxy class files. |
||
71 | * |
||
72 | * @return string|null |
||
73 | */ |
||
74 | 2387 | public function getProxyDir() |
|
80 | |||
81 | /** |
||
82 | * Gets the strategy for automatically generating proxy classes. |
||
83 | * |
||
84 | * @return int Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory. |
||
85 | */ |
||
86 | 2389 | public function getAutoGenerateProxyClasses() |
|
92 | |||
93 | /** |
||
94 | * Sets the strategy for automatically generating proxy classes. |
||
95 | * |
||
96 | * @param boolean|int $autoGenerate Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory. |
||
97 | * True is converted to AUTOGENERATE_ALWAYS, false to AUTOGENERATE_NEVER. |
||
98 | * |
||
99 | * @return void |
||
100 | */ |
||
101 | 15 | public function setAutoGenerateProxyClasses($autoGenerate) |
|
105 | |||
106 | /** |
||
107 | * Gets the namespace where proxy classes reside. |
||
108 | * |
||
109 | * @return string|null |
||
110 | */ |
||
111 | 2386 | public function getProxyNamespace() |
|
117 | |||
118 | /** |
||
119 | * Sets the namespace where proxy classes reside. |
||
120 | * |
||
121 | * @param string $ns |
||
122 | * |
||
123 | * @return void |
||
124 | */ |
||
125 | 2391 | public function setProxyNamespace($ns) |
|
129 | |||
130 | /** |
||
131 | * Sets the cache driver implementation that is used for metadata caching. |
||
132 | * |
||
133 | * @param MappingDriver $driverImpl |
||
134 | * |
||
135 | * @return void |
||
136 | * |
||
137 | * @todo Force parameter to be a Closure to ensure lazy evaluation |
||
138 | * (as soon as a metadata cache is in effect, the driver never needs to initialize). |
||
139 | */ |
||
140 | 2390 | public function setMetadataDriverImpl(MappingDriver $driverImpl) |
|
144 | |||
145 | /** |
||
146 | * Adds a new default annotation driver with a correctly configured annotation reader. If $useSimpleAnnotationReader |
||
147 | * is true, the notation `@Entity` will work, otherwise, the notation `@ORM\Entity` will be supported. |
||
148 | * |
||
149 | * @param array $paths |
||
150 | * @param bool $useSimpleAnnotationReader |
||
151 | * |
||
152 | * @return AnnotationDriver |
||
153 | */ |
||
154 | 2366 | public function newDefaultAnnotationDriver($paths = [], $useSimpleAnnotationReader = true) |
|
172 | |||
173 | /** |
||
174 | * Adds a namespace under a certain alias. |
||
175 | * |
||
176 | * @param string $alias |
||
177 | * @param string $namespace |
||
178 | * |
||
179 | * @return void |
||
180 | */ |
||
181 | 8 | public function addEntityNamespace($alias, $namespace) |
|
185 | |||
186 | /** |
||
187 | * Resolves a registered namespace alias to the full namespace. |
||
188 | * |
||
189 | * @param string $entityNamespaceAlias |
||
190 | * |
||
191 | * @return string |
||
192 | * |
||
193 | * @throws ORMException |
||
194 | */ |
||
195 | 13 | public function getEntityNamespace($entityNamespaceAlias) |
|
203 | |||
204 | /** |
||
205 | * Sets the entity alias map. |
||
206 | * |
||
207 | * @param array $entityNamespaces |
||
208 | * |
||
209 | * @return void |
||
210 | */ |
||
211 | 97 | public function setEntityNamespaces(array $entityNamespaces) |
|
215 | |||
216 | /** |
||
217 | * Retrieves the list of registered entity namespace aliases. |
||
218 | * |
||
219 | * @return array |
||
220 | */ |
||
221 | 1 | public function getEntityNamespaces() |
|
225 | |||
226 | /** |
||
227 | * Gets the cache driver implementation that is used for the mapping metadata. |
||
228 | * |
||
229 | * @return MappingDriver|null |
||
230 | * |
||
231 | * @throws ORMException |
||
232 | */ |
||
233 | 1522 | public function getMetadataDriverImpl() |
|
239 | |||
240 | /** |
||
241 | * Gets the cache driver implementation that is used for the query cache (SQL cache). |
||
242 | * |
||
243 | * @return \Doctrine\Common\Cache\Cache|null |
||
244 | */ |
||
245 | 578 | public function getQueryCacheImpl() |
|
251 | |||
252 | /** |
||
253 | * Sets the cache driver implementation that is used for the query cache (SQL cache). |
||
254 | * |
||
255 | * @param \Doctrine\Common\Cache\Cache $cacheImpl |
||
256 | * |
||
257 | * @return void |
||
258 | */ |
||
259 | 2327 | public function setQueryCacheImpl(CacheDriver $cacheImpl) |
|
263 | |||
264 | /** |
||
265 | * Gets the cache driver implementation that is used for the hydration cache (SQL cache). |
||
266 | * |
||
267 | * @return \Doctrine\Common\Cache\Cache|null |
||
268 | */ |
||
269 | 1 | public function getHydrationCacheImpl() |
|
275 | |||
276 | /** |
||
277 | * Sets the cache driver implementation that is used for the hydration cache (SQL cache). |
||
278 | * |
||
279 | * @param \Doctrine\Common\Cache\Cache $cacheImpl |
||
280 | * |
||
281 | * @return void |
||
282 | */ |
||
283 | 1 | public function setHydrationCacheImpl(CacheDriver $cacheImpl) |
|
287 | |||
288 | /** |
||
289 | * Gets the cache driver implementation that is used for metadata caching. |
||
290 | * |
||
291 | * @return \Doctrine\Common\Cache\Cache|null |
||
292 | */ |
||
293 | 2393 | public function getMetadataCacheImpl() |
|
299 | |||
300 | /** |
||
301 | * Sets the cache driver implementation that is used for metadata caching. |
||
302 | * |
||
303 | * @param \Doctrine\Common\Cache\Cache $cacheImpl |
||
304 | * |
||
305 | * @return void |
||
306 | */ |
||
307 | 2327 | public function setMetadataCacheImpl(CacheDriver $cacheImpl) |
|
311 | |||
312 | /** |
||
313 | * Adds a named DQL query to the configuration. |
||
314 | * |
||
315 | * @param string $name The name of the query. |
||
316 | * @param string $dql The DQL query string. |
||
317 | * |
||
318 | * @return void |
||
319 | */ |
||
320 | 1 | public function addNamedQuery($name, $dql) |
|
324 | |||
325 | /** |
||
326 | * Gets a previously registered named DQL query. |
||
327 | * |
||
328 | * @param string $name The name of the query. |
||
329 | * |
||
330 | * @return string The DQL query. |
||
331 | * |
||
332 | * @throws ORMException |
||
333 | */ |
||
334 | 1 | public function getNamedQuery($name) |
|
342 | |||
343 | /** |
||
344 | * Adds a named native query to the configuration. |
||
345 | * |
||
346 | * @param string $name The name of the query. |
||
347 | * @param string $sql The native SQL query string. |
||
348 | * @param Query\ResultSetMapping $rsm The ResultSetMapping used for the results of the SQL query. |
||
349 | * |
||
350 | * @return void |
||
351 | */ |
||
352 | 1 | public function addNamedNativeQuery($name, $sql, Query\ResultSetMapping $rsm) |
|
356 | |||
357 | /** |
||
358 | * Gets the components of a previously registered named native query. |
||
359 | * |
||
360 | * @param string $name The name of the query. |
||
361 | * |
||
362 | * @return array A tuple with the first element being the SQL string and the second |
||
363 | * element being the ResultSetMapping. |
||
364 | * |
||
365 | * @throws ORMException |
||
366 | */ |
||
367 | 1 | public function getNamedNativeQuery($name) |
|
375 | |||
376 | /** |
||
377 | * Ensures that this Configuration instance contains settings that are |
||
378 | * suitable for a production environment. |
||
379 | * |
||
380 | * @return void |
||
381 | * |
||
382 | * @throws ORMException If a configuration setting has a value that is not |
||
383 | * suitable for a production environment. |
||
384 | */ |
||
385 | 8 | public function ensureProductionSettings() |
|
411 | |||
412 | /** |
||
413 | * Registers a custom DQL function that produces a string value. |
||
414 | * Such a function can then be used in any DQL statement in any place where string |
||
415 | * functions are allowed. |
||
416 | * |
||
417 | * DQL function names are case-insensitive. |
||
418 | * |
||
419 | * @param string $name Function name. |
||
420 | * @param string|callable $className Class name or a callable that returns the function. |
||
421 | * |
||
422 | * @return void |
||
423 | * |
||
424 | * @throws ORMException |
||
425 | */ |
||
426 | 4 | public function addCustomStringFunction($name, $className) |
|
430 | |||
431 | /** |
||
432 | * Gets the implementation class name of a registered custom string DQL function. |
||
433 | * |
||
434 | * @param string $name |
||
435 | * |
||
436 | * @return string|null |
||
437 | */ |
||
438 | 142 | public function getCustomStringFunction($name) |
|
446 | |||
447 | /** |
||
448 | * Sets a map of custom DQL string functions. |
||
449 | * |
||
450 | * Keys must be function names and values the FQCN of the implementing class. |
||
451 | * The function names will be case-insensitive in DQL. |
||
452 | * |
||
453 | * Any previously added string functions are discarded. |
||
454 | * |
||
455 | * @param array $functions The map of custom DQL string functions. |
||
456 | * |
||
457 | * @return void |
||
458 | */ |
||
459 | 1 | public function setCustomStringFunctions(array $functions) |
|
465 | |||
466 | /** |
||
467 | * Registers a custom DQL function that produces a numeric value. |
||
468 | * Such a function can then be used in any DQL statement in any place where numeric |
||
469 | * functions are allowed. |
||
470 | * |
||
471 | * DQL function names are case-insensitive. |
||
472 | * |
||
473 | * @param string $name Function name. |
||
474 | * @param string|callable $className Class name or a callable that returns the function. |
||
475 | * |
||
476 | * @return void |
||
477 | * |
||
478 | * @throws ORMException |
||
479 | */ |
||
480 | 3 | public function addCustomNumericFunction($name, $className) |
|
484 | |||
485 | /** |
||
486 | * Gets the implementation class name of a registered custom numeric DQL function. |
||
487 | * |
||
488 | * @param string $name |
||
489 | * |
||
490 | * @return string|null |
||
491 | */ |
||
492 | 140 | public function getCustomNumericFunction($name) |
|
500 | |||
501 | /** |
||
502 | * Sets a map of custom DQL numeric functions. |
||
503 | * |
||
504 | * Keys must be function names and values the FQCN of the implementing class. |
||
505 | * The function names will be case-insensitive in DQL. |
||
506 | * |
||
507 | * Any previously added numeric functions are discarded. |
||
508 | * |
||
509 | * @param array $functions The map of custom DQL numeric functions. |
||
510 | * |
||
511 | * @return void |
||
512 | */ |
||
513 | 2 | public function setCustomNumericFunctions(array $functions) |
|
519 | |||
520 | /** |
||
521 | * Registers a custom DQL function that produces a date/time value. |
||
522 | * Such a function can then be used in any DQL statement in any place where date/time |
||
523 | * functions are allowed. |
||
524 | * |
||
525 | * DQL function names are case-insensitive. |
||
526 | * |
||
527 | * @param string $name Function name. |
||
528 | * @param string|callable $className Class name or a callable that returns the function. |
||
529 | * |
||
530 | * @return void |
||
531 | * |
||
532 | * @throws ORMException |
||
533 | */ |
||
534 | 1 | public function addCustomDatetimeFunction($name, $className) |
|
538 | |||
539 | /** |
||
540 | * Gets the implementation class name of a registered custom date/time DQL function. |
||
541 | * |
||
542 | * @param string $name |
||
543 | * |
||
544 | * @return string|null |
||
545 | */ |
||
546 | 138 | public function getCustomDatetimeFunction($name) |
|
554 | |||
555 | /** |
||
556 | * Sets a map of custom DQL date/time functions. |
||
557 | * |
||
558 | * Keys must be function names and values the FQCN of the implementing class. |
||
559 | * The function names will be case-insensitive in DQL. |
||
560 | * |
||
561 | * Any previously added date/time functions are discarded. |
||
562 | * |
||
563 | * @param array $functions The map of custom DQL date/time functions. |
||
564 | * |
||
565 | * @return void |
||
566 | */ |
||
567 | 1 | public function setCustomDatetimeFunctions(array $functions) |
|
573 | |||
574 | /** |
||
575 | * Sets the custom hydrator modes in one pass. |
||
576 | * |
||
577 | * @param array $modes An array of ($modeName => $hydrator). |
||
578 | * |
||
579 | * @return void |
||
580 | */ |
||
581 | 1 | public function setCustomHydrationModes($modes) |
|
589 | |||
590 | /** |
||
591 | * Gets the hydrator class for the given hydration mode name. |
||
592 | * |
||
593 | * @param string $modeName The hydration mode name. |
||
594 | * |
||
595 | * @return string|null The hydrator class name. |
||
596 | */ |
||
597 | 3 | public function getCustomHydrationMode($modeName) |
|
603 | |||
604 | /** |
||
605 | * Adds a custom hydration mode. |
||
606 | * |
||
607 | * @param string $modeName The hydration mode name. |
||
608 | * @param string $hydrator The hydrator class name. |
||
609 | * |
||
610 | * @return void |
||
611 | */ |
||
612 | 3 | public function addCustomHydrationMode($modeName, $hydrator) |
|
616 | |||
617 | /** |
||
618 | * Sets a class metadata factory. |
||
619 | * |
||
620 | * @param string $cmfName |
||
621 | * |
||
622 | * @return void |
||
623 | */ |
||
624 | 1 | public function setClassMetadataFactoryName($cmfName) |
|
628 | |||
629 | /** |
||
630 | * @return string |
||
631 | */ |
||
632 | 2385 | public function getClassMetadataFactoryName() |
|
640 | |||
641 | /** |
||
642 | * Adds a filter to the list of possible filters. |
||
643 | * |
||
644 | * @param string $name The name of the filter. |
||
645 | * @param string $className The class name of the filter. |
||
646 | */ |
||
647 | 46 | public function addFilter($name, $className) |
|
651 | |||
652 | /** |
||
653 | * Gets the class name for a given filter name. |
||
654 | * |
||
655 | * @param string $name The name of the filter. |
||
656 | * |
||
657 | * @return string The class name of the filter, or null if it is not |
||
658 | * defined. |
||
659 | */ |
||
660 | 45 | public function getFilterClassName($name) |
|
666 | |||
667 | /** |
||
668 | * Sets default repository class. |
||
669 | * |
||
670 | * @since 2.2 |
||
671 | * |
||
672 | * @param string $className |
||
673 | * |
||
674 | * @return void |
||
675 | * |
||
676 | * @throws ORMException If not is a \Doctrine\Common\Persistence\ObjectRepository |
||
677 | */ |
||
678 | 3 | public function setDefaultRepositoryClassName($className) |
|
688 | |||
689 | /** |
||
690 | * Get default repository class. |
||
691 | * |
||
692 | * @since 2.2 |
||
693 | * |
||
694 | * @return string |
||
695 | */ |
||
696 | 150 | public function getDefaultRepositoryClassName() |
|
702 | |||
703 | /** |
||
704 | * Sets naming strategy. |
||
705 | * |
||
706 | * @since 2.3 |
||
707 | * |
||
708 | * @param NamingStrategy $namingStrategy |
||
709 | * |
||
710 | * @return void |
||
711 | */ |
||
712 | 7 | public function setNamingStrategy(NamingStrategy $namingStrategy) |
|
716 | |||
717 | /** |
||
718 | * Gets naming strategy.. |
||
719 | * |
||
720 | * @since 2.3 |
||
721 | * |
||
722 | * @return NamingStrategy |
||
723 | */ |
||
724 | 449 | public function getNamingStrategy() |
|
732 | |||
733 | /** |
||
734 | * Sets quote strategy. |
||
735 | * |
||
736 | * @since 2.3 |
||
737 | * |
||
738 | * @param \Doctrine\ORM\Mapping\QuoteStrategy $quoteStrategy |
||
739 | * |
||
740 | * @return void |
||
741 | */ |
||
742 | 2 | public function setQuoteStrategy(QuoteStrategy $quoteStrategy) |
|
746 | |||
747 | /** |
||
748 | * Gets quote strategy. |
||
749 | * |
||
750 | * @since 2.3 |
||
751 | * |
||
752 | * @return \Doctrine\ORM\Mapping\QuoteStrategy |
||
753 | */ |
||
754 | 1638 | public function getQuoteStrategy() |
|
762 | |||
763 | /** |
||
764 | * Set the entity listener resolver. |
||
765 | * |
||
766 | * @since 2.4 |
||
767 | * @param \Doctrine\ORM\Mapping\EntityListenerResolver $resolver |
||
768 | */ |
||
769 | 1 | public function setEntityListenerResolver(EntityListenerResolver $resolver) |
|
773 | |||
774 | /** |
||
775 | * Get the entity listener resolver. |
||
776 | * |
||
777 | * @since 2.4 |
||
778 | * @return \Doctrine\ORM\Mapping\EntityListenerResolver |
||
779 | */ |
||
780 | 2385 | public function getEntityListenerResolver() |
|
788 | |||
789 | /** |
||
790 | * Set the entity repository factory. |
||
791 | * |
||
792 | * @since 2.4 |
||
793 | * @param \Doctrine\ORM\Repository\RepositoryFactory $repositoryFactory |
||
794 | */ |
||
795 | public function setRepositoryFactory(RepositoryFactory $repositoryFactory) |
||
799 | |||
800 | /** |
||
801 | * Get the entity repository factory. |
||
802 | * |
||
803 | * @since 2.4 |
||
804 | * @return \Doctrine\ORM\Repository\RepositoryFactory |
||
805 | */ |
||
806 | 2384 | public function getRepositoryFactory() |
|
812 | |||
813 | /** |
||
814 | * @since 2.5 |
||
815 | * |
||
816 | * @return boolean |
||
817 | */ |
||
818 | 2385 | public function isSecondLevelCacheEnabled() |
|
824 | |||
825 | /** |
||
826 | * @since 2.5 |
||
827 | * |
||
828 | * @param boolean $flag |
||
829 | * |
||
830 | * @return void |
||
831 | */ |
||
832 | 282 | public function setSecondLevelCacheEnabled($flag = true) |
|
836 | |||
837 | /** |
||
838 | * @since 2.5 |
||
839 | * |
||
840 | * @param \Doctrine\ORM\Cache\CacheConfiguration $cacheConfig |
||
841 | * |
||
842 | * @return void |
||
843 | */ |
||
844 | 283 | public function setSecondLevelCacheConfiguration(CacheConfiguration $cacheConfig) |
|
848 | |||
849 | /** |
||
850 | * @since 2.5 |
||
851 | * |
||
852 | * @return \Doctrine\ORM\Cache\CacheConfiguration|null |
||
853 | */ |
||
854 | 283 | public function getSecondLevelCacheConfiguration() |
|
864 | |||
865 | /** |
||
866 | * Returns query hints, which will be applied to every query in application |
||
867 | * |
||
868 | * @since 2.5 |
||
869 | * |
||
870 | * @return array |
||
871 | */ |
||
872 | 955 | public function getDefaultQueryHints() |
|
876 | |||
877 | /** |
||
878 | * Sets array of query hints, which will be applied to every query in application |
||
879 | * |
||
880 | * @since 2.5 |
||
881 | * |
||
882 | * @param array $defaultQueryHints |
||
883 | */ |
||
884 | 1 | public function setDefaultQueryHints(array $defaultQueryHints) |
|
888 | |||
889 | /** |
||
890 | * Gets the value of a default query hint. If the hint name is not recognized, FALSE is returned. |
||
891 | * |
||
892 | * @since 2.5 |
||
893 | * |
||
894 | * @param string $name The name of the hint. |
||
895 | * |
||
896 | * @return mixed The value of the hint or FALSE, if the hint name is not recognized. |
||
897 | */ |
||
898 | public function getDefaultQueryHint($name) |
||
904 | |||
905 | /** |
||
906 | * Sets a default query hint. If the hint name is not recognized, it is silently ignored. |
||
907 | * |
||
908 | * @since 2.5 |
||
909 | * |
||
910 | * @param string $name The name of the hint. |
||
911 | * @param mixed $value The value of the hint. |
||
912 | */ |
||
913 | 1 | public function setDefaultQueryHint($name, $value) |
|
917 | } |
||
918 |
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: