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 |
||
48 | class Configuration extends \Doctrine\MongoDB\Configuration |
||
49 | { |
||
50 | /** |
||
51 | * Never autogenerate a proxy/hydrator/persistent collection and rely that |
||
52 | * it was generated by some process before deployment. Copied from |
||
53 | * \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
54 | * |
||
55 | * @var integer |
||
56 | */ |
||
57 | const AUTOGENERATE_NEVER = 0; |
||
58 | |||
59 | /** |
||
60 | * Always generates a new proxy/hydrator/persistent collection in every request. |
||
61 | * |
||
62 | * This is only sane during development. |
||
63 | * Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
64 | * |
||
65 | * @var integer |
||
66 | */ |
||
67 | const AUTOGENERATE_ALWAYS = 1; |
||
68 | |||
69 | /** |
||
70 | * Autogenerate the proxy/hydrator/persistent collection class when the file does not exist. |
||
71 | * |
||
72 | * This strategy causes a file exists call whenever any proxy/hydrator is used the |
||
73 | * first time in a request. Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
74 | * |
||
75 | * @var integer |
||
76 | */ |
||
77 | const AUTOGENERATE_FILE_NOT_EXISTS = 2; |
||
78 | |||
79 | /** |
||
80 | * Generate the proxy/hydrator/persistent collection classes using eval(). |
||
81 | * |
||
82 | * This strategy is only sane for development. |
||
83 | * Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
84 | * |
||
85 | * @var integer |
||
86 | */ |
||
87 | const AUTOGENERATE_EVAL = 3; |
||
88 | |||
89 | /** |
||
90 | * Adds a namespace under a certain alias. |
||
91 | * |
||
92 | * @param string $alias |
||
93 | * @param string $namespace |
||
94 | */ |
||
95 | public function addDocumentNamespace($alias, $namespace) |
||
99 | |||
100 | /** |
||
101 | * Resolves a registered namespace alias to the full namespace. |
||
102 | * |
||
103 | * @param string $documentNamespaceAlias |
||
104 | * @return string |
||
105 | * @throws MongoDBException |
||
106 | */ |
||
107 | public function getDocumentNamespace($documentNamespaceAlias) |
||
115 | |||
116 | /** |
||
117 | * Retrieves the list of registered document namespace aliases. |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | public function getDocumentNamespaces() |
||
125 | |||
126 | /** |
||
127 | * Set the document alias map |
||
128 | * |
||
129 | * @param array $documentNamespaces |
||
130 | * @return void |
||
131 | */ |
||
132 | public function setDocumentNamespaces(array $documentNamespaces) |
||
136 | |||
137 | /** |
||
138 | * Sets the cache driver implementation that is used for metadata caching. |
||
139 | * |
||
140 | * @param MappingDriver $driverImpl |
||
141 | * @todo Force parameter to be a Closure to ensure lazy evaluation |
||
142 | * (as soon as a metadata cache is in effect, the driver never needs to initialize). |
||
143 | */ |
||
144 | 962 | public function setMetadataDriverImpl(MappingDriver $driverImpl) |
|
148 | |||
149 | /** |
||
150 | * Add a new default annotation driver with a correctly configured annotation reader. |
||
151 | * |
||
152 | * @param array $paths |
||
153 | * @return Mapping\Driver\AnnotationDriver |
||
154 | */ |
||
155 | public function newDefaultAnnotationDriver($paths = array()) |
||
161 | |||
162 | /** |
||
163 | * Gets the cache driver implementation that is used for the mapping metadata. |
||
164 | * |
||
165 | * @return MappingDriver |
||
166 | */ |
||
167 | 773 | public function getMetadataDriverImpl() |
|
172 | |||
173 | /** |
||
174 | * Gets the cache driver implementation that is used for metadata caching. |
||
175 | * |
||
176 | * @return \Doctrine\Common\Cache\Cache |
||
177 | */ |
||
178 | 946 | public function getMetadataCacheImpl() |
|
183 | |||
184 | /** |
||
185 | * Sets the cache driver implementation that is used for metadata caching. |
||
186 | * |
||
187 | * @param \Doctrine\Common\Cache\Cache $cacheImpl |
||
188 | */ |
||
189 | public function setMetadataCacheImpl(Cache $cacheImpl) |
||
193 | |||
194 | /** |
||
195 | * Sets the directory where Doctrine generates any necessary proxy class files. |
||
196 | * |
||
197 | * @param string $dir |
||
198 | */ |
||
199 | 946 | public function setProxyDir($dir) |
|
203 | |||
204 | /** |
||
205 | * Gets the directory where Doctrine generates any necessary proxy class files. |
||
206 | * |
||
207 | * @return string |
||
208 | */ |
||
209 | 946 | public function getProxyDir() |
|
214 | |||
215 | /** |
||
216 | * Gets a boolean flag that indicates whether proxy classes should always be regenerated |
||
217 | * during each script execution. |
||
218 | * |
||
219 | * @return boolean|integer |
||
220 | */ |
||
221 | 946 | public function getAutoGenerateProxyClasses() |
|
226 | |||
227 | /** |
||
228 | * Sets a boolean flag that indicates whether proxy classes should always be regenerated |
||
229 | * during each script execution. |
||
230 | * |
||
231 | * @param boolean|int $bool Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory |
||
232 | */ |
||
233 | public function setAutoGenerateProxyClasses($bool) |
||
237 | |||
238 | /** |
||
239 | * Gets the namespace where proxy classes reside. |
||
240 | * |
||
241 | * @return string |
||
242 | */ |
||
243 | 946 | public function getProxyNamespace() |
|
248 | |||
249 | /** |
||
250 | * Sets the namespace where proxy classes reside. |
||
251 | * |
||
252 | * @param string $ns |
||
253 | */ |
||
254 | 946 | public function setProxyNamespace($ns) |
|
258 | |||
259 | /** |
||
260 | * Sets the directory where Doctrine generates hydrator class files. |
||
261 | * |
||
262 | * @param string $dir |
||
263 | */ |
||
264 | 946 | public function setHydratorDir($dir) |
|
268 | |||
269 | /** |
||
270 | * Gets the directory where Doctrine generates hydrator class files. |
||
271 | * |
||
272 | * @return string |
||
273 | */ |
||
274 | 946 | public function getHydratorDir() |
|
279 | |||
280 | /** |
||
281 | * Gets a boolean flag that indicates whether hydrator classes should always be regenerated |
||
282 | * during each script execution. |
||
283 | * |
||
284 | * @return boolean|integer Possible values are defined constants |
||
285 | */ |
||
286 | 946 | public function getAutoGenerateHydratorClasses() |
|
291 | |||
292 | /** |
||
293 | * Sets a boolean flag that indicates whether hydrator classes should always be regenerated |
||
294 | * during each script execution. |
||
295 | * |
||
296 | * @param boolean|integer $bool |
||
297 | */ |
||
298 | public function setAutoGenerateHydratorClasses($bool) |
||
302 | |||
303 | /** |
||
304 | * Gets the namespace where hydrator classes reside. |
||
305 | * |
||
306 | * @return string |
||
307 | */ |
||
308 | 946 | public function getHydratorNamespace() |
|
313 | |||
314 | /** |
||
315 | * Sets the namespace where hydrator classes reside. |
||
316 | * |
||
317 | * @param string $ns |
||
318 | */ |
||
319 | 946 | public function setHydratorNamespace($ns) |
|
323 | |||
324 | /** |
||
325 | * Sets the directory where Doctrine generates persistent collection class files. |
||
326 | * |
||
327 | * @param string $dir |
||
328 | */ |
||
329 | 946 | public function setPersistentCollectionDir($dir) |
|
333 | |||
334 | /** |
||
335 | * Gets the directory where Doctrine generates persistent collection class files. |
||
336 | * |
||
337 | * @return string |
||
338 | */ |
||
339 | public function getPersistentCollectionDir() |
||
344 | |||
345 | /** |
||
346 | * Gets a integer flag that indicates how and when persistent collection |
||
347 | * classes should be generated. |
||
348 | * |
||
349 | * @return integer Possible values are defined constants |
||
350 | */ |
||
351 | 4 | public function getAutoGeneratePersistentCollectionClasses() |
|
356 | |||
357 | /** |
||
358 | * Sets a integer flag that indicates how and when persistent collection |
||
359 | * classes should be generated. |
||
360 | * |
||
361 | * @param integer $mode Possible values are defined constants |
||
362 | */ |
||
363 | public function setAutoGeneratePersistentCollectionClasses($mode) |
||
367 | |||
368 | /** |
||
369 | * Gets the namespace where persistent collection classes reside. |
||
370 | * |
||
371 | * @return string |
||
372 | */ |
||
373 | public function getPersistentCollectionNamespace() |
||
378 | |||
379 | /** |
||
380 | * Sets the namespace where persistent collection classes reside. |
||
381 | * |
||
382 | * @param string $ns |
||
383 | */ |
||
384 | 946 | public function setPersistentCollectionNamespace($ns) |
|
388 | |||
389 | /** |
||
390 | * Sets the default DB to use for all Documents that do not specify |
||
391 | * a database. |
||
392 | * |
||
393 | * @param string $defaultDB |
||
394 | */ |
||
395 | 946 | public function setDefaultDB($defaultDB) |
|
399 | |||
400 | /** |
||
401 | * Gets the default DB to use for all Documents that do not specify a database. |
||
402 | * |
||
403 | * @return string $defaultDB |
||
404 | */ |
||
405 | 694 | public function getDefaultDB() |
|
410 | |||
411 | /** |
||
412 | * Set the class metadata factory class name. |
||
413 | * |
||
414 | * @param string $cmfName |
||
415 | */ |
||
416 | public function setClassMetadataFactoryName($cmfName) |
||
420 | |||
421 | /** |
||
422 | * Gets the class metadata factory class name. |
||
423 | * |
||
424 | * @return string |
||
425 | */ |
||
426 | 946 | public function getClassMetadataFactoryName() |
|
433 | |||
434 | /** |
||
435 | * Gets array of default commit options. |
||
436 | * |
||
437 | * @return array |
||
438 | */ |
||
439 | 563 | public function getDefaultCommitOptions() |
|
447 | |||
448 | /** |
||
449 | * Sets array of default commit options. |
||
450 | * |
||
451 | * @param boolean $defaultCommitOptions |
||
452 | */ |
||
453 | public function setDefaultCommitOptions($defaultCommitOptions) |
||
457 | |||
458 | /** |
||
459 | * Add a filter to the list of possible filters. |
||
460 | * |
||
461 | * @param string $name The name of the filter. |
||
462 | * @param string $className The class name of the filter. |
||
463 | * @param array $parameters The parameters for the filter. |
||
464 | */ |
||
465 | 946 | public function addFilter($name, $className, array $parameters = array()) |
|
472 | |||
473 | /** |
||
474 | * Gets the class name for a given filter name. |
||
475 | * |
||
476 | * @param string $name The name of the filter. |
||
477 | * |
||
478 | * @return string|null The filter class name, or null if it is undefined |
||
479 | */ |
||
480 | 22 | public function getFilterClassName($name) |
|
486 | |||
487 | /** |
||
488 | * Gets the parameters for a given filter name. |
||
489 | * |
||
490 | * @param string $name The name of the filter. |
||
491 | * |
||
492 | * @return array|null The filter parameters, or null if it is undefined |
||
493 | */ |
||
494 | 21 | public function getFilterParameters($name) |
|
500 | |||
501 | /** |
||
502 | * Sets default repository class. |
||
503 | * |
||
504 | * @param string $className |
||
505 | * |
||
506 | * @return void |
||
507 | * |
||
508 | * @throws MongoDBException If not is a ObjectRepository |
||
509 | */ |
||
510 | public function setDefaultRepositoryClassName($className) |
||
520 | |||
521 | /** |
||
522 | * Get default repository class. |
||
523 | * |
||
524 | * @return string |
||
525 | */ |
||
526 | 328 | public function getDefaultRepositoryClassName() |
|
532 | |||
533 | /** |
||
534 | * Set the document repository factory. |
||
535 | * |
||
536 | * @param RepositoryFactory $repositoryFactory |
||
537 | */ |
||
538 | public function setRepositoryFactory(RepositoryFactory $repositoryFactory) |
||
542 | |||
543 | /** |
||
544 | * Get the document repository factory. |
||
545 | * |
||
546 | * @return RepositoryFactory |
||
547 | */ |
||
548 | 946 | public function getRepositoryFactory() |
|
554 | |||
555 | /** |
||
556 | * Set the persistent collection factory. |
||
557 | * |
||
558 | * @param PersistentCollectionFactory $persistentCollectionFactory |
||
559 | */ |
||
560 | public function setPersistentCollectionFactory(PersistentCollectionFactory $persistentCollectionFactory) |
||
564 | |||
565 | /** |
||
566 | * Get the persistent collection factory. |
||
567 | * |
||
568 | * @return DefaultPersistentCollectionFactory |
||
569 | */ |
||
570 | 387 | public function getPersistentCollectionFactory() |
|
577 | |||
578 | /** |
||
579 | * Set the persistent collection generator. |
||
580 | * |
||
581 | * @param PersistentCollectionGenerator $persistentCollectionGenerator |
||
582 | */ |
||
583 | public function setPersistentCollectionGenerator(PersistentCollectionGenerator $persistentCollectionGenerator) |
||
587 | |||
588 | /** |
||
589 | * Get the persistent collection generator. |
||
590 | * |
||
591 | * @return DefaultPersistentCollectionGenerator |
||
592 | */ |
||
593 | 5 | public function getPersistentCollectionGenerator() |
|
603 | } |
||
604 |