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 | * Sets the cache driver implementation that is used for metadata caching. |
||
130 | * |
||
131 | * @param MappingDriver $driverImpl |
||
132 | * |
||
133 | * @return void |
||
134 | * |
||
135 | * @todo Force parameter to be a Closure to ensure lazy evaluation |
||
136 | * (as soon as a metadata cache is in effect, the driver never needs to initialize). |
||
137 | */ |
||
138 | 2353 | public function setMetadataDriverImpl(MappingDriver $driverImpl) |
|
142 | |||
143 | /** |
||
144 | * Adds a new default annotation driver with a correctly configured annotation reader. If $useSimpleAnnotationReader |
||
145 | * is true, the notation `@Entity` will work, otherwise, the notation `@ORM\Entity` will be supported. |
||
146 | * |
||
147 | * @param array $paths |
||
148 | * @param bool $useSimpleAnnotationReader |
||
149 | * |
||
150 | * @return AnnotationDriver |
||
151 | */ |
||
152 | 2329 | public function newDefaultAnnotationDriver($paths = array(), $useSimpleAnnotationReader = true) |
|
170 | |||
171 | /** |
||
172 | * Adds a namespace under a certain alias. |
||
173 | * |
||
174 | * @param string $alias |
||
175 | * @param string $namespace |
||
176 | * |
||
177 | * @return void |
||
178 | */ |
||
179 | 8 | public function addEntityNamespace($alias, $namespace) |
|
183 | |||
184 | /** |
||
185 | * Resolves a registered namespace alias to the full namespace. |
||
186 | * |
||
187 | * @param string $entityNamespaceAlias |
||
188 | * |
||
189 | * @return string |
||
190 | * |
||
191 | * @throws ORMException |
||
192 | */ |
||
193 | 13 | public function getEntityNamespace($entityNamespaceAlias) |
|
201 | |||
202 | /** |
||
203 | * Sets the entity alias map. |
||
204 | * |
||
205 | * @param array $entityNamespaces |
||
206 | * |
||
207 | * @return void |
||
208 | */ |
||
209 | 95 | public function setEntityNamespaces(array $entityNamespaces) |
|
213 | |||
214 | /** |
||
215 | * Retrieves the list of registered entity namespace aliases. |
||
216 | * |
||
217 | * @return array |
||
218 | */ |
||
219 | 1 | public function getEntityNamespaces() |
|
223 | |||
224 | /** |
||
225 | * Gets the cache driver implementation that is used for the mapping metadata. |
||
226 | * |
||
227 | * @return MappingDriver|null |
||
228 | * |
||
229 | * @throws ORMException |
||
230 | */ |
||
231 | 1489 | public function getMetadataDriverImpl() |
|
237 | |||
238 | /** |
||
239 | * Gets the cache driver implementation that is used for the query cache (SQL cache). |
||
240 | * |
||
241 | * @return \Doctrine\Common\Cache\Cache|null |
||
242 | */ |
||
243 | 569 | public function getQueryCacheImpl() |
|
249 | |||
250 | /** |
||
251 | * Sets the cache driver implementation that is used for the query cache (SQL cache). |
||
252 | * |
||
253 | * @param \Doctrine\Common\Cache\Cache $cacheImpl |
||
254 | * |
||
255 | * @return void |
||
256 | */ |
||
257 | 2295 | public function setQueryCacheImpl(CacheDriver $cacheImpl) |
|
261 | |||
262 | /** |
||
263 | * Gets the cache driver implementation that is used for the hydration cache (SQL cache). |
||
264 | * |
||
265 | * @return \Doctrine\Common\Cache\Cache|null |
||
266 | */ |
||
267 | 1 | public function getHydrationCacheImpl() |
|
273 | |||
274 | /** |
||
275 | * Sets the cache driver implementation that is used for the hydration cache (SQL cache). |
||
276 | * |
||
277 | * @param \Doctrine\Common\Cache\Cache $cacheImpl |
||
278 | * |
||
279 | * @return void |
||
280 | */ |
||
281 | 1 | public function setHydrationCacheImpl(CacheDriver $cacheImpl) |
|
285 | |||
286 | /** |
||
287 | * Gets the cache driver implementation that is used for metadata caching. |
||
288 | * |
||
289 | * @return \Doctrine\Common\Cache\Cache|null |
||
290 | */ |
||
291 | 2356 | public function getMetadataCacheImpl() |
|
297 | |||
298 | /** |
||
299 | * Sets the cache driver implementation that is used for metadata caching. |
||
300 | * |
||
301 | * @param \Doctrine\Common\Cache\Cache $cacheImpl |
||
302 | * |
||
303 | * @return void |
||
304 | */ |
||
305 | 2295 | public function setMetadataCacheImpl(CacheDriver $cacheImpl) |
|
309 | |||
310 | /** |
||
311 | * Adds a named DQL query to the configuration. |
||
312 | * |
||
313 | * @param string $name The name of the query. |
||
314 | * @param string $dql The DQL query string. |
||
315 | * |
||
316 | * @return void |
||
317 | */ |
||
318 | 1 | public function addNamedQuery($name, $dql) |
|
322 | |||
323 | /** |
||
324 | * Gets a previously registered named DQL query. |
||
325 | * |
||
326 | * @param string $name The name of the query. |
||
327 | * |
||
328 | * @return string The DQL query. |
||
329 | * |
||
330 | * @throws ORMException |
||
331 | */ |
||
332 | 1 | public function getNamedQuery($name) |
|
340 | |||
341 | /** |
||
342 | * Adds a named native query to the configuration. |
||
343 | * |
||
344 | * @param string $name The name of the query. |
||
345 | * @param string $sql The native SQL query string. |
||
346 | * @param Query\ResultSetMapping $rsm The ResultSetMapping used for the results of the SQL query. |
||
347 | * |
||
348 | * @return void |
||
349 | */ |
||
350 | 1 | public function addNamedNativeQuery($name, $sql, Query\ResultSetMapping $rsm) |
|
354 | |||
355 | /** |
||
356 | * Gets the components of a previously registered named native query. |
||
357 | * |
||
358 | * @param string $name The name of the query. |
||
359 | * |
||
360 | * @return array A tuple with the first element being the SQL string and the second |
||
361 | * element being the ResultSetMapping. |
||
362 | * |
||
363 | * @throws ORMException |
||
364 | */ |
||
365 | 1 | public function getNamedNativeQuery($name) |
|
366 | { |
||
367 | 1 | if ( ! isset($this->_attributes['namedNativeQueries'][$name])) { |
|
368 | 1 | throw ORMException::namedNativeQueryNotFound($name); |
|
369 | } |
||
370 | |||
371 | 1 | return $this->_attributes['namedNativeQueries'][$name]; |
|
372 | } |
||
373 | |||
374 | /** |
||
375 | * Ensures that this Configuration instance contains settings that are |
||
376 | * suitable for a production environment. |
||
377 | * |
||
378 | * @return void |
||
379 | * |
||
380 | * @throws ORMException If a configuration setting has a value that is not |
||
381 | * suitable for a production environment. |
||
382 | */ |
||
383 | 8 | public function ensureProductionSettings() |
|
409 | |||
410 | /** |
||
411 | * Registers a custom DQL function that produces a string value. |
||
412 | * Such a function can then be used in any DQL statement in any place where string |
||
413 | * functions are allowed. |
||
414 | * |
||
415 | * DQL function names are case-insensitive. |
||
416 | * |
||
417 | * @param string $name Function name. |
||
418 | * @param string|callable $className Class name or a callable that returns the function. |
||
419 | * |
||
420 | * @return void |
||
421 | * |
||
422 | * @throws ORMException |
||
423 | */ |
||
424 | 3 | public function addCustomStringFunction($name, $className) |
|
432 | |||
433 | /** |
||
434 | * Gets the implementation class name of a registered custom string DQL function. |
||
435 | * |
||
436 | * @param string $name |
||
437 | * |
||
438 | * @return string|null |
||
439 | */ |
||
440 | 4 | public function getCustomStringFunction($name) |
|
448 | |||
449 | /** |
||
450 | * Sets a map of custom DQL string functions. |
||
451 | * |
||
452 | * Keys must be function names and values the FQCN of the implementing class. |
||
453 | * The function names will be case-insensitive in DQL. |
||
454 | * |
||
455 | * Any previously added string functions are discarded. |
||
456 | * |
||
457 | * @param array $functions The map of custom DQL string functions. |
||
458 | * |
||
459 | * @return void |
||
460 | */ |
||
461 | 1 | public function setCustomStringFunctions(array $functions) |
|
467 | |||
468 | /** |
||
469 | * Registers a custom DQL function that produces a numeric value. |
||
470 | * Such a function can then be used in any DQL statement in any place where numeric |
||
471 | * functions are allowed. |
||
472 | * |
||
473 | * DQL function names are case-insensitive. |
||
474 | * |
||
475 | * @param string $name Function name. |
||
476 | * @param string|callable $className Class name or a callable that returns the function. |
||
477 | * |
||
478 | * @return void |
||
479 | * |
||
480 | * @throws ORMException |
||
481 | */ |
||
482 | 3 | public function addCustomNumericFunction($name, $className) |
|
490 | |||
491 | /** |
||
492 | * Gets the implementation class name of a registered custom numeric DQL function. |
||
493 | * |
||
494 | * @param string $name |
||
495 | * |
||
496 | * @return string|null |
||
497 | */ |
||
498 | 3 | public function getCustomNumericFunction($name) |
|
506 | |||
507 | /** |
||
508 | * Sets a map of custom DQL numeric functions. |
||
509 | * |
||
510 | * Keys must be function names and values the FQCN of the implementing class. |
||
511 | * The function names will be case-insensitive in DQL. |
||
512 | * |
||
513 | * Any previously added numeric functions are discarded. |
||
514 | * |
||
515 | * @param array $functions The map of custom DQL numeric functions. |
||
516 | * |
||
517 | * @return void |
||
518 | */ |
||
519 | 2 | public function setCustomNumericFunctions(array $functions) |
|
525 | |||
526 | /** |
||
527 | * Registers a custom DQL function that produces a date/time value. |
||
528 | * Such a function can then be used in any DQL statement in any place where date/time |
||
529 | * functions are allowed. |
||
530 | * |
||
531 | * DQL function names are case-insensitive. |
||
532 | * |
||
533 | * @param string $name Function name. |
||
534 | * @param string|callable $className Class name or a callable that returns the function. |
||
535 | * |
||
536 | * @return void |
||
537 | * |
||
538 | * @throws ORMException |
||
539 | */ |
||
540 | 1 | public function addCustomDatetimeFunction($name, $className) |
|
548 | |||
549 | /** |
||
550 | * Gets the implementation class name of a registered custom date/time DQL function. |
||
551 | * |
||
552 | * @param string $name |
||
553 | * |
||
554 | * @return string|null |
||
555 | */ |
||
556 | 1 | public function getCustomDatetimeFunction($name) |
|
564 | |||
565 | /** |
||
566 | * Sets a map of custom DQL date/time functions. |
||
567 | * |
||
568 | * Keys must be function names and values the FQCN of the implementing class. |
||
569 | * The function names will be case-insensitive in DQL. |
||
570 | * |
||
571 | * Any previously added date/time functions are discarded. |
||
572 | * |
||
573 | * @param array $functions The map of custom DQL date/time functions. |
||
574 | * |
||
575 | * @return void |
||
576 | */ |
||
577 | 1 | public function setCustomDatetimeFunctions(array $functions) |
|
583 | |||
584 | /** |
||
585 | * Sets the custom hydrator modes in one pass. |
||
586 | * |
||
587 | * @param array $modes An array of ($modeName => $hydrator). |
||
588 | * |
||
589 | * @return void |
||
590 | */ |
||
591 | 1 | public function setCustomHydrationModes($modes) |
|
599 | |||
600 | /** |
||
601 | * Gets the hydrator class for the given hydration mode name. |
||
602 | * |
||
603 | * @param string $modeName The hydration mode name. |
||
604 | * |
||
605 | * @return string|null The hydrator class name. |
||
606 | */ |
||
607 | 3 | public function getCustomHydrationMode($modeName) |
|
613 | |||
614 | /** |
||
615 | * Adds a custom hydration mode. |
||
616 | * |
||
617 | * @param string $modeName The hydration mode name. |
||
618 | * @param string $hydrator The hydrator class name. |
||
619 | * |
||
620 | * @return void |
||
621 | */ |
||
622 | 3 | public function addCustomHydrationMode($modeName, $hydrator) |
|
626 | |||
627 | /** |
||
628 | * Sets a class metadata factory. |
||
629 | * |
||
630 | * @param string $cmfName |
||
631 | * |
||
632 | * @return void |
||
633 | */ |
||
634 | 1 | public function setClassMetadataFactoryName($cmfName) |
|
638 | |||
639 | /** |
||
640 | * @return string |
||
641 | */ |
||
642 | 2348 | public function getClassMetadataFactoryName() |
|
650 | |||
651 | /** |
||
652 | * Adds a filter to the list of possible filters. |
||
653 | * |
||
654 | * @param string $name The name of the filter. |
||
655 | * @param string $className The class name of the filter. |
||
656 | */ |
||
657 | 46 | public function addFilter($name, $className) |
|
661 | |||
662 | /** |
||
663 | * Gets the class name for a given filter name. |
||
664 | * |
||
665 | * @param string $name The name of the filter. |
||
666 | * |
||
667 | * @return string The class name of the filter, or null if it is not |
||
668 | * defined. |
||
669 | */ |
||
670 | 45 | public function getFilterClassName($name) |
|
676 | |||
677 | /** |
||
678 | * Sets default repository class. |
||
679 | * |
||
680 | * @since 2.2 |
||
681 | * |
||
682 | * @param string $className |
||
683 | * |
||
684 | * @return void |
||
685 | * |
||
686 | * @throws ORMException If not is a \Doctrine\Common\Persistence\ObjectRepository |
||
687 | */ |
||
688 | 3 | public function setDefaultRepositoryClassName($className) |
|
698 | |||
699 | /** |
||
700 | * Get default repository class. |
||
701 | * |
||
702 | * @since 2.2 |
||
703 | * |
||
704 | * @return string |
||
705 | */ |
||
706 | 142 | public function getDefaultRepositoryClassName() |
|
712 | |||
713 | /** |
||
714 | * Sets naming strategy. |
||
715 | * |
||
716 | * @since 2.3 |
||
717 | * |
||
718 | * @param NamingStrategy $namingStrategy |
||
719 | * |
||
720 | * @return void |
||
721 | */ |
||
722 | 7 | public function setNamingStrategy(NamingStrategy $namingStrategy) |
|
726 | |||
727 | /** |
||
728 | * Gets naming strategy.. |
||
729 | * |
||
730 | * @since 2.3 |
||
731 | * |
||
732 | * @return NamingStrategy |
||
733 | */ |
||
734 | 428 | public function getNamingStrategy() |
|
742 | |||
743 | /** |
||
744 | * Sets quote strategy. |
||
745 | * |
||
746 | * @since 2.3 |
||
747 | * |
||
748 | * @param \Doctrine\ORM\Mapping\QuoteStrategy $quoteStrategy |
||
749 | * |
||
750 | * @return void |
||
751 | */ |
||
752 | 2 | public function setQuoteStrategy(QuoteStrategy $quoteStrategy) |
|
756 | |||
757 | /** |
||
758 | * Gets quote strategy. |
||
759 | * |
||
760 | * @since 2.3 |
||
761 | * |
||
762 | * @return \Doctrine\ORM\Mapping\QuoteStrategy |
||
763 | */ |
||
764 | 1615 | public function getQuoteStrategy() |
|
772 | |||
773 | /** |
||
774 | * Set the entity listener resolver. |
||
775 | * |
||
776 | * @since 2.4 |
||
777 | * @param \Doctrine\ORM\Mapping\EntityListenerResolver $resolver |
||
778 | */ |
||
779 | 1 | public function setEntityListenerResolver(EntityListenerResolver $resolver) |
|
783 | |||
784 | /** |
||
785 | * Get the entity listener resolver. |
||
786 | * |
||
787 | * @since 2.4 |
||
788 | * @return \Doctrine\ORM\Mapping\EntityListenerResolver |
||
789 | */ |
||
790 | 2348 | public function getEntityListenerResolver() |
|
798 | |||
799 | /** |
||
800 | * Set the entity repository factory. |
||
801 | * |
||
802 | * @since 2.4 |
||
803 | * @param \Doctrine\ORM\Repository\RepositoryFactory $repositoryFactory |
||
804 | */ |
||
805 | public function setRepositoryFactory(RepositoryFactory $repositoryFactory) |
||
809 | |||
810 | /** |
||
811 | * Get the entity repository factory. |
||
812 | * |
||
813 | * @since 2.4 |
||
814 | * @return \Doctrine\ORM\Repository\RepositoryFactory |
||
815 | */ |
||
816 | 2347 | public function getRepositoryFactory() |
|
822 | |||
823 | /** |
||
824 | * @since 2.5 |
||
825 | * |
||
826 | * @return boolean |
||
827 | */ |
||
828 | 2348 | public function isSecondLevelCacheEnabled() |
|
834 | |||
835 | /** |
||
836 | * @since 2.5 |
||
837 | * |
||
838 | * @param boolean $flag |
||
839 | * |
||
840 | * @return void |
||
841 | */ |
||
842 | 278 | public function setSecondLevelCacheEnabled($flag = true) |
|
846 | |||
847 | /** |
||
848 | * @since 2.5 |
||
849 | * |
||
850 | * @param \Doctrine\ORM\Cache\CacheConfiguration $cacheConfig |
||
851 | * |
||
852 | * @return void |
||
853 | */ |
||
854 | 279 | public function setSecondLevelCacheConfiguration(CacheConfiguration $cacheConfig) |
|
858 | |||
859 | /** |
||
860 | * @since 2.5 |
||
861 | * |
||
862 | * @return \Doctrine\ORM\Cache\CacheConfiguration|null |
||
863 | */ |
||
864 | 279 | public function getSecondLevelCacheConfiguration() |
|
874 | |||
875 | /** |
||
876 | * Returns query hints, which will be applied to every query in application |
||
877 | * |
||
878 | * @since 2.5 |
||
879 | * |
||
880 | * @return array |
||
881 | */ |
||
882 | 946 | public function getDefaultQueryHints() |
|
886 | |||
887 | /** |
||
888 | * Sets array of query hints, which will be applied to every query in application |
||
889 | * |
||
890 | * @since 2.5 |
||
891 | * |
||
892 | * @param array $defaultQueryHints |
||
893 | */ |
||
894 | 1 | public function setDefaultQueryHints(array $defaultQueryHints) |
|
898 | |||
899 | /** |
||
900 | * Gets the value of a default query hint. If the hint name is not recognized, FALSE is returned. |
||
901 | * |
||
902 | * @since 2.5 |
||
903 | * |
||
904 | * @param string $name The name of the hint. |
||
905 | * |
||
906 | * @return mixed The value of the hint or FALSE, if the hint name is not recognized. |
||
907 | */ |
||
908 | public function getDefaultQueryHint($name) |
||
914 | |||
915 | /** |
||
916 | * Sets a default query hint. If the hint name is not recognized, it is silently ignored. |
||
917 | * |
||
918 | * @since 2.5 |
||
919 | * |
||
920 | * @param string $name The name of the hint. |
||
921 | * @param mixed $value The value of the hint. |
||
922 | */ |
||
923 | 1 | public function setDefaultQueryHint($name, $value) |
|
927 | } |
||
928 |
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: