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 |
||
46 | class Configuration extends \Doctrine\MongoDB\Configuration |
||
47 | { |
||
48 | /** |
||
49 | * Never autogenerate a proxy/hydrator/persistent collection and rely that |
||
50 | * it was generated by some process before deployment. Copied from |
||
51 | * \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
52 | * |
||
53 | * @var integer |
||
54 | */ |
||
55 | const AUTOGENERATE_NEVER = 0; |
||
56 | |||
57 | /** |
||
58 | * Always generates a new proxy/hydrator/persistent collection in every request. |
||
59 | * |
||
60 | * This is only sane during development. |
||
61 | * Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
62 | * |
||
63 | * @var integer |
||
64 | */ |
||
65 | const AUTOGENERATE_ALWAYS = 1; |
||
66 | |||
67 | /** |
||
68 | * Autogenerate the proxy/hydrator/persistent collection class when the file does not exist. |
||
69 | * |
||
70 | * This strategy causes a file exists call whenever any proxy/hydrator is used the |
||
71 | * first time in a request. Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
72 | * |
||
73 | * @var integer |
||
74 | */ |
||
75 | const AUTOGENERATE_FILE_NOT_EXISTS = 2; |
||
76 | |||
77 | /** |
||
78 | * Generate the proxy/hydrator/persistent collection classes using eval(). |
||
79 | * |
||
80 | * This strategy is only sane for development. |
||
81 | * Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
82 | * |
||
83 | * @var integer |
||
84 | */ |
||
85 | const AUTOGENERATE_EVAL = 3; |
||
86 | |||
87 | /** |
||
88 | * Adds a namespace under a certain alias. |
||
89 | * |
||
90 | * @param string $alias |
||
91 | * @param string $namespace |
||
92 | */ |
||
93 | public function addDocumentNamespace($alias, $namespace) |
||
97 | |||
98 | /** |
||
99 | * Resolves a registered namespace alias to the full namespace. |
||
100 | * |
||
101 | * @param string $documentNamespaceAlias |
||
102 | * @return string |
||
103 | * @throws MongoDBException |
||
104 | */ |
||
105 | public function getDocumentNamespace($documentNamespaceAlias) |
||
113 | |||
114 | /** |
||
115 | * Retrieves the list of registered document namespace aliases. |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | public function getDocumentNamespaces() |
||
123 | |||
124 | /** |
||
125 | * Set the document alias map |
||
126 | * |
||
127 | * @param array $documentNamespaces |
||
128 | * @return void |
||
129 | */ |
||
130 | public function setDocumentNamespaces(array $documentNamespaces) |
||
134 | |||
135 | /** |
||
136 | * Sets the cache driver implementation that is used for metadata caching. |
||
137 | * |
||
138 | * @param MappingDriver $driverImpl |
||
139 | * @todo Force parameter to be a Closure to ensure lazy evaluation |
||
140 | * (as soon as a metadata cache is in effect, the driver never needs to initialize). |
||
141 | */ |
||
142 | 945 | public function setMetadataDriverImpl(MappingDriver $driverImpl) |
|
146 | |||
147 | /** |
||
148 | * Add a new default annotation driver with a correctly configured annotation reader. |
||
149 | * |
||
150 | * @param array $paths |
||
151 | * @return Mapping\Driver\AnnotationDriver |
||
152 | */ |
||
153 | public function newDefaultAnnotationDriver($paths = array()) |
||
159 | |||
160 | /** |
||
161 | * Gets the cache driver implementation that is used for the mapping metadata. |
||
162 | * |
||
163 | * @return MappingDriver |
||
164 | */ |
||
165 | 760 | public function getMetadataDriverImpl() |
|
170 | |||
171 | /** |
||
172 | * Gets the cache driver implementation that is used for metadata caching. |
||
173 | * |
||
174 | * @return \Doctrine\Common\Cache\Cache |
||
175 | */ |
||
176 | 929 | public function getMetadataCacheImpl() |
|
181 | |||
182 | /** |
||
183 | * Sets the cache driver implementation that is used for metadata caching. |
||
184 | * |
||
185 | * @param \Doctrine\Common\Cache\Cache $cacheImpl |
||
186 | */ |
||
187 | public function setMetadataCacheImpl(Cache $cacheImpl) |
||
191 | |||
192 | /** |
||
193 | * Sets the directory where Doctrine generates any necessary proxy class files. |
||
194 | * |
||
195 | * @param string $dir |
||
196 | */ |
||
197 | 929 | public function setProxyDir($dir) |
|
201 | |||
202 | /** |
||
203 | * Gets the directory where Doctrine generates any necessary proxy class files. |
||
204 | * |
||
205 | * @return string |
||
206 | */ |
||
207 | 929 | public function getProxyDir() |
|
212 | |||
213 | /** |
||
214 | * Gets a boolean flag that indicates whether proxy classes should always be regenerated |
||
215 | * during each script execution. |
||
216 | * |
||
217 | * @return boolean|integer |
||
218 | */ |
||
219 | 929 | public function getAutoGenerateProxyClasses() |
|
224 | |||
225 | /** |
||
226 | * Sets a boolean flag that indicates whether proxy classes should always be regenerated |
||
227 | * during each script execution. |
||
228 | * |
||
229 | * @param boolean|int $bool Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory |
||
230 | */ |
||
231 | public function setAutoGenerateProxyClasses($bool) |
||
235 | |||
236 | /** |
||
237 | * Gets the namespace where proxy classes reside. |
||
238 | * |
||
239 | * @return string |
||
240 | */ |
||
241 | 929 | public function getProxyNamespace() |
|
246 | |||
247 | /** |
||
248 | * Sets the namespace where proxy classes reside. |
||
249 | * |
||
250 | * @param string $ns |
||
251 | */ |
||
252 | 929 | public function setProxyNamespace($ns) |
|
256 | |||
257 | /** |
||
258 | * Sets the directory where Doctrine generates hydrator class files. |
||
259 | * |
||
260 | * @param string $dir |
||
261 | */ |
||
262 | 929 | public function setHydratorDir($dir) |
|
266 | |||
267 | /** |
||
268 | * Gets the directory where Doctrine generates hydrator class files. |
||
269 | * |
||
270 | * @return string |
||
271 | */ |
||
272 | 929 | public function getHydratorDir() |
|
277 | |||
278 | /** |
||
279 | * Gets a boolean flag that indicates whether hydrator classes should always be regenerated |
||
280 | * during each script execution. |
||
281 | * |
||
282 | * @return boolean|integer Possible values are defined constants |
||
283 | */ |
||
284 | 929 | public function getAutoGenerateHydratorClasses() |
|
289 | |||
290 | /** |
||
291 | * Sets a boolean flag that indicates whether hydrator classes should always be regenerated |
||
292 | * during each script execution. |
||
293 | * |
||
294 | * @param boolean|integer $bool |
||
295 | */ |
||
296 | public function setAutoGenerateHydratorClasses($bool) |
||
300 | |||
301 | /** |
||
302 | * Gets the namespace where hydrator classes reside. |
||
303 | * |
||
304 | * @return string |
||
305 | */ |
||
306 | 929 | public function getHydratorNamespace() |
|
311 | |||
312 | /** |
||
313 | * Sets the namespace where hydrator classes reside. |
||
314 | * |
||
315 | * @param string $ns |
||
316 | */ |
||
317 | 929 | public function setHydratorNamespace($ns) |
|
321 | |||
322 | /** |
||
323 | * Sets the directory where Doctrine generates persistent collection class files. |
||
324 | * |
||
325 | * @param string $dir |
||
326 | */ |
||
327 | 929 | public function setPersistentCollectionDir($dir) |
|
331 | |||
332 | /** |
||
333 | * Gets the directory where Doctrine generates persistent collection class files. |
||
334 | * |
||
335 | * @return string |
||
336 | */ |
||
337 | 929 | public function getPersistentCollectionDir() |
|
342 | |||
343 | /** |
||
344 | * Gets a integer flag that indicates how and when persistent collection |
||
345 | * classes should be generated. |
||
346 | * |
||
347 | * @return integer Possible values are defined constants |
||
348 | */ |
||
349 | 929 | public function getAutoGeneratePersistentCollectionClasses() |
|
354 | |||
355 | /** |
||
356 | * Sets a integer flag that indicates how and when persistent collection |
||
357 | * classes should be generated. |
||
358 | * |
||
359 | * @param integer $mode Possible values are defined constants |
||
360 | */ |
||
361 | public function setAutoGeneratePersistentCollectionClasses($mode) |
||
365 | |||
366 | /** |
||
367 | * Gets the namespace where persistent collection classes reside. |
||
368 | * |
||
369 | * @return string |
||
370 | */ |
||
371 | 929 | public function getPersistentCollectionNamespace() |
|
376 | |||
377 | /** |
||
378 | * Sets the namespace where persistent collection classes reside. |
||
379 | * |
||
380 | * @param string $ns |
||
381 | */ |
||
382 | 929 | public function setPersistentCollectionNamespace($ns) |
|
386 | |||
387 | /** |
||
388 | * Sets the default DB to use for all Documents that do not specify |
||
389 | * a database. |
||
390 | * |
||
391 | * @param string $defaultDB |
||
392 | */ |
||
393 | 929 | public function setDefaultDB($defaultDB) |
|
397 | |||
398 | /** |
||
399 | * Gets the default DB to use for all Documents that do not specify a database. |
||
400 | * |
||
401 | * @return string $defaultDB |
||
402 | */ |
||
403 | 681 | public function getDefaultDB() |
|
408 | |||
409 | /** |
||
410 | * Set the class metadata factory class name. |
||
411 | * |
||
412 | * @param string $cmfName |
||
413 | */ |
||
414 | public function setClassMetadataFactoryName($cmfName) |
||
418 | |||
419 | /** |
||
420 | * Gets the class metadata factory class name. |
||
421 | * |
||
422 | * @return string |
||
423 | */ |
||
424 | 929 | public function getClassMetadataFactoryName() |
|
431 | |||
432 | /** |
||
433 | * Gets array of default commit options. |
||
434 | * |
||
435 | * @return array |
||
436 | */ |
||
437 | 559 | public function getDefaultCommitOptions() |
|
445 | |||
446 | /** |
||
447 | * Sets array of default commit options. |
||
448 | * |
||
449 | * @param boolean $defaultCommitOptions |
||
450 | */ |
||
451 | public function setDefaultCommitOptions($defaultCommitOptions) |
||
455 | |||
456 | /** |
||
457 | * Add a filter to the list of possible filters. |
||
458 | * |
||
459 | * @param string $name The name of the filter. |
||
460 | * @param string $className The class name of the filter. |
||
461 | * @param array $parameters The parameters for the filter. |
||
462 | */ |
||
463 | 929 | public function addFilter($name, $className, array $parameters = array()) |
|
470 | |||
471 | /** |
||
472 | * Gets the class name for a given filter name. |
||
473 | * |
||
474 | * @param string $name The name of the filter. |
||
475 | * |
||
476 | * @return string|null The filter class name, or null if it is undefined |
||
477 | */ |
||
478 | 22 | public function getFilterClassName($name) |
|
484 | |||
485 | /** |
||
486 | * Gets the parameters for a given filter name. |
||
487 | * |
||
488 | * @param string $name The name of the filter. |
||
489 | * |
||
490 | * @return array|null The filter parameters, or null if it is undefined |
||
491 | */ |
||
492 | 21 | public function getFilterParameters($name) |
|
498 | |||
499 | /** |
||
500 | * Sets default repository class. |
||
501 | * |
||
502 | * @param string $className |
||
503 | * |
||
504 | * @return void |
||
505 | * |
||
506 | * @throws MongoDBException If not is a ObjectRepository |
||
507 | */ |
||
508 | public function setDefaultRepositoryClassName($className) |
||
518 | |||
519 | /** |
||
520 | * Get default repository class. |
||
521 | * |
||
522 | * @return string |
||
523 | */ |
||
524 | 324 | public function getDefaultRepositoryClassName() |
|
530 | |||
531 | /** |
||
532 | * Set the document repository factory. |
||
533 | * |
||
534 | * @param RepositoryFactory $repositoryFactory |
||
535 | */ |
||
536 | public function setRepositoryFactory(RepositoryFactory $repositoryFactory) |
||
540 | |||
541 | /** |
||
542 | * Get the document repository factory. |
||
543 | * |
||
544 | * @return RepositoryFactory |
||
545 | */ |
||
546 | 929 | public function getRepositoryFactory() |
|
552 | } |
||
553 |