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 |
||
35 | class Configuration |
||
36 | { |
||
37 | /** |
||
38 | * Array of attributes for this configuration instance. |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | private $attributes = []; |
||
43 | |||
44 | /** |
||
45 | * Never autogenerate a proxy/hydrator/persistent collection and rely that |
||
46 | * it was generated by some process before deployment. Copied from |
||
47 | * \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
48 | * |
||
49 | * @var integer |
||
50 | */ |
||
51 | public const AUTOGENERATE_NEVER = 0; |
||
52 | |||
53 | /** |
||
54 | * Always generates a new proxy/hydrator/persistent collection in every request. |
||
55 | * |
||
56 | * This is only sane during development. |
||
57 | * Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
58 | * |
||
59 | * @var integer |
||
60 | */ |
||
61 | public const AUTOGENERATE_ALWAYS = 1; |
||
62 | |||
63 | /** |
||
64 | * Autogenerate the proxy/hydrator/persistent collection class when the file does not exist. |
||
65 | * |
||
66 | * This strategy causes a file exists call whenever any proxy/hydrator is used the |
||
67 | * first time in a request. Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
68 | * |
||
69 | * @var integer |
||
70 | */ |
||
71 | public const AUTOGENERATE_FILE_NOT_EXISTS = 2; |
||
72 | |||
73 | /** |
||
74 | * Generate the proxy/hydrator/persistent collection classes using eval(). |
||
75 | * |
||
76 | * This strategy is only sane for development. |
||
77 | * Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
78 | * |
||
79 | * @var integer |
||
80 | */ |
||
81 | public const AUTOGENERATE_EVAL = 3; |
||
82 | |||
83 | /** |
||
84 | * Adds a namespace under a certain alias. |
||
85 | * |
||
86 | * @param string $alias |
||
87 | * @param string $namespace |
||
88 | */ |
||
89 | public function addDocumentNamespace($alias, $namespace) |
||
93 | |||
94 | /** |
||
95 | * Resolves a registered namespace alias to the full namespace. |
||
96 | * |
||
97 | * @param string $documentNamespaceAlias |
||
98 | * @return string |
||
99 | * @throws MongoDBException |
||
100 | */ |
||
101 | public function getDocumentNamespace($documentNamespaceAlias) |
||
109 | |||
110 | /** |
||
111 | * Retrieves the list of registered document namespace aliases. |
||
112 | * |
||
113 | * @return array |
||
114 | */ |
||
115 | public function getDocumentNamespaces() |
||
119 | |||
120 | /** |
||
121 | * Set the document alias map |
||
122 | * |
||
123 | * @param array $documentNamespaces |
||
124 | */ |
||
125 | public function setDocumentNamespaces(array $documentNamespaces) |
||
129 | |||
130 | /** |
||
131 | * Sets the cache driver implementation that is used for metadata caching. |
||
132 | * |
||
133 | 1623 | * @todo Force parameter to be a Closure to ensure lazy evaluation |
|
134 | * (as soon as a metadata cache is in effect, the driver never needs to initialize). |
||
135 | 1623 | */ |
|
136 | 1623 | public function setMetadataDriverImpl(MappingDriver $driverImpl) |
|
140 | |||
141 | /** |
||
142 | * Add a new default annotation driver with a correctly configured annotation reader. |
||
143 | * |
||
144 | * @param array $paths |
||
145 | * @return Mapping\Driver\AnnotationDriver |
||
146 | */ |
||
147 | public function newDefaultAnnotationDriver($paths = []) |
||
153 | |||
154 | /** |
||
155 | * Gets the cache driver implementation that is used for the mapping metadata. |
||
156 | 1365 | * |
|
157 | * @return MappingDriver |
||
158 | 1365 | */ |
|
159 | public function getMetadataDriverImpl() |
||
163 | |||
164 | /** |
||
165 | * Gets the cache driver implementation that is used for metadata caching. |
||
166 | 1580 | * |
|
167 | * @return Cache |
||
168 | 1580 | */ |
|
169 | public function getMetadataCacheImpl() |
||
173 | |||
174 | /** |
||
175 | * Sets the cache driver implementation that is used for metadata caching. |
||
176 | * |
||
177 | */ |
||
178 | public function setMetadataCacheImpl(Cache $cacheImpl) |
||
182 | |||
183 | /** |
||
184 | * Sets the directory where Doctrine generates any necessary proxy class files. |
||
185 | 1580 | * |
|
186 | * @param string $dir |
||
187 | 1580 | */ |
|
188 | 1580 | public function setProxyDir($dir) |
|
192 | |||
193 | /** |
||
194 | * Gets the directory where Doctrine generates any necessary proxy class files. |
||
195 | 1580 | * |
|
196 | * @return string |
||
197 | 1580 | */ |
|
198 | public function getProxyDir() |
||
202 | |||
203 | /** |
||
204 | * Gets a boolean flag that indicates whether proxy classes should always be regenerated |
||
205 | * during each script execution. |
||
206 | 1580 | * |
|
207 | * @return bool|int |
||
208 | 1580 | */ |
|
209 | public function getAutoGenerateProxyClasses() |
||
213 | |||
214 | /** |
||
215 | * Sets a boolean flag that indicates whether proxy classes should always be regenerated |
||
216 | * during each script execution. |
||
217 | * |
||
218 | * @param bool|int $bool Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory |
||
219 | */ |
||
220 | public function setAutoGenerateProxyClasses($bool) |
||
224 | |||
225 | /** |
||
226 | * Gets the namespace where proxy classes reside. |
||
227 | 1580 | * |
|
228 | * @return string |
||
229 | 1580 | */ |
|
230 | public function getProxyNamespace() |
||
234 | |||
235 | /** |
||
236 | * Sets the namespace where proxy classes reside. |
||
237 | 1580 | * |
|
238 | * @param string $ns |
||
239 | 1580 | */ |
|
240 | 1580 | public function setProxyNamespace($ns) |
|
244 | |||
245 | /** |
||
246 | * Sets the directory where Doctrine generates hydrator class files. |
||
247 | 1580 | * |
|
248 | * @param string $dir |
||
249 | 1580 | */ |
|
250 | 1580 | public function setHydratorDir($dir) |
|
254 | |||
255 | /** |
||
256 | * Gets the directory where Doctrine generates hydrator class files. |
||
257 | 1580 | * |
|
258 | * @return string |
||
259 | 1580 | */ |
|
260 | public function getHydratorDir() |
||
264 | |||
265 | /** |
||
266 | * Gets a boolean flag that indicates whether hydrator classes should always be regenerated |
||
267 | * during each script execution. |
||
268 | 1580 | * |
|
269 | * @return bool|int Possible values are defined constants |
||
270 | 1580 | */ |
|
271 | public function getAutoGenerateHydratorClasses() |
||
275 | |||
276 | /** |
||
277 | * Sets a boolean flag that indicates whether hydrator classes should always be regenerated |
||
278 | * during each script execution. |
||
279 | * |
||
280 | * @param bool|int $bool |
||
281 | */ |
||
282 | public function setAutoGenerateHydratorClasses($bool) |
||
286 | |||
287 | /** |
||
288 | * Gets the namespace where hydrator classes reside. |
||
289 | 1580 | * |
|
290 | * @return string |
||
291 | 1580 | */ |
|
292 | public function getHydratorNamespace() |
||
296 | |||
297 | /** |
||
298 | * Sets the namespace where hydrator classes reside. |
||
299 | 1580 | * |
|
300 | * @param string $ns |
||
301 | 1580 | */ |
|
302 | 1580 | public function setHydratorNamespace($ns) |
|
306 | |||
307 | /** |
||
308 | * Sets the directory where Doctrine generates persistent collection class files. |
||
309 | 1580 | * |
|
310 | * @param string $dir |
||
311 | 1580 | */ |
|
312 | 1580 | public function setPersistentCollectionDir($dir) |
|
316 | |||
317 | /** |
||
318 | * Gets the directory where Doctrine generates persistent collection class files. |
||
319 | 11 | * |
|
320 | * @return string |
||
321 | 11 | */ |
|
322 | public function getPersistentCollectionDir() |
||
326 | |||
327 | /** |
||
328 | * Gets a integer flag that indicates how and when persistent collection |
||
329 | * classes should be generated. |
||
330 | 7 | * |
|
331 | * @return int Possible values are defined constants |
||
332 | 7 | */ |
|
333 | public function getAutoGeneratePersistentCollectionClasses() |
||
337 | |||
338 | /** |
||
339 | * Sets a integer flag that indicates how and when persistent collection |
||
340 | * classes should be generated. |
||
341 | * |
||
342 | * @param int $mode Possible values are defined constants |
||
343 | */ |
||
344 | public function setAutoGeneratePersistentCollectionClasses($mode) |
||
348 | |||
349 | /** |
||
350 | * Gets the namespace where persistent collection classes reside. |
||
351 | 11 | * |
|
352 | * @return string |
||
353 | 11 | */ |
|
354 | public function getPersistentCollectionNamespace() |
||
358 | |||
359 | /** |
||
360 | * Sets the namespace where persistent collection classes reside. |
||
361 | 1580 | * |
|
362 | * @param string $ns |
||
363 | 1580 | */ |
|
364 | 1580 | public function setPersistentCollectionNamespace($ns) |
|
368 | |||
369 | /** |
||
370 | * Sets the default DB to use for all Documents that do not specify |
||
371 | * a database. |
||
372 | 1580 | * |
|
373 | * @param string $defaultDB |
||
374 | 1580 | */ |
|
375 | 1580 | public function setDefaultDB($defaultDB) |
|
379 | |||
380 | /** |
||
381 | * Gets the default DB to use for all Documents that do not specify a database. |
||
382 | 1248 | * |
|
383 | * @return string $defaultDB |
||
384 | 1248 | */ |
|
385 | public function getDefaultDB() |
||
389 | |||
390 | /** |
||
391 | * Set the class metadata factory class name. |
||
392 | * |
||
393 | * @param string $cmfName |
||
394 | */ |
||
395 | public function setClassMetadataFactoryName($cmfName) |
||
399 | |||
400 | /** |
||
401 | * Gets the class metadata factory class name. |
||
402 | 1580 | * |
|
403 | * @return string |
||
404 | 1580 | */ |
|
405 | 1580 | public function getClassMetadataFactoryName() |
|
412 | |||
413 | /** |
||
414 | * Gets array of default commit options. |
||
415 | 548 | * |
|
416 | * @return array |
||
417 | 548 | */ |
|
418 | public function getDefaultCommitOptions() |
||
422 | |||
423 | /** |
||
424 | * Sets array of default commit options. |
||
425 | 1 | * |
|
426 | * @param array $defaultCommitOptions |
||
427 | 1 | */ |
|
428 | 1 | public function setDefaultCommitOptions($defaultCommitOptions) |
|
432 | |||
433 | /** |
||
434 | * Add a filter to the list of possible filters. |
||
435 | * |
||
436 | * @param string $name The name of the filter. |
||
437 | 1580 | * @param string $className The class name of the filter. |
|
438 | * @param array $parameters The parameters for the filter. |
||
439 | 1580 | */ |
|
440 | 1580 | public function addFilter($name, $className, array $parameters = []) |
|
447 | |||
448 | /** |
||
449 | * Gets the class name for a given filter name. |
||
450 | * |
||
451 | * @param string $name The name of the filter. |
||
452 | 24 | * |
|
453 | * @return string|null The filter class name, or null if it is undefined |
||
454 | 24 | */ |
|
455 | 24 | public function getFilterClassName($name) |
|
461 | |||
462 | /** |
||
463 | * Gets the parameters for a given filter name. |
||
464 | * |
||
465 | * @param string $name The name of the filter. |
||
466 | 23 | * |
|
467 | * @return array|null The filter parameters, or null if it is undefined |
||
468 | 23 | */ |
|
469 | 23 | public function getFilterParameters($name) |
|
475 | |||
476 | /** |
||
477 | * Sets default repository class for documents. |
||
478 | * |
||
479 | * @param string $className |
||
480 | * |
||
481 | * @throws MongoDBException If the class does not implement the ObjectRepository interface. |
||
482 | */ |
||
483 | public function setDefaultDocumentRepositoryClassName($className) |
||
493 | |||
494 | /** |
||
495 | * Get default repository class for documents. |
||
496 | * |
||
497 | 317 | * @return string |
|
498 | */ |
||
499 | 317 | public function getDefaultDocumentRepositoryClassName() |
|
503 | |||
504 | /** |
||
505 | * Sets default repository class for GridFS files. |
||
506 | 2 | * |
|
507 | * @param string $className |
||
508 | 2 | * |
|
509 | 2 | * @throws MongoDBException If the class does not implement the GridFSRepository interface. |
|
510 | */ |
||
511 | public function setDefaultGridFSRepositoryClassName($className) |
||
521 | |||
522 | /** |
||
523 | * Get default repository class for GridFS files. |
||
524 | * |
||
525 | * @return string |
||
526 | */ |
||
527 | public function getDefaultGridFSRepositoryClassName() |
||
531 | |||
532 | /** |
||
533 | * Set the document repository factory. |
||
534 | * |
||
535 | 387 | */ |
|
536 | public function setRepositoryFactory(RepositoryFactory $repositoryFactory) |
||
540 | 387 | ||
541 | /** |
||
542 | * Get the document repository factory. |
||
543 | * |
||
544 | * @return RepositoryFactory |
||
545 | */ |
||
546 | public function getRepositoryFactory() |
||
550 | |||
551 | /** |
||
552 | * Set the persistent collection factory. |
||
553 | * |
||
554 | */ |
||
555 | public function setPersistentCollectionFactory(PersistentCollectionFactory $persistentCollectionFactory) |
||
559 | 8 | ||
560 | 8 | /** |
|
561 | 8 | * Get the persistent collection factory. |
|
562 | 8 | * |
|
563 | * @return DefaultPersistentCollectionFactory |
||
564 | */ |
||
565 | 8 | public function getPersistentCollectionFactory() |
|
572 | |||
573 | /** |
||
574 | * Set the persistent collection generator. |
||
575 | * |
||
576 | */ |
||
577 | public function setPersistentCollectionGenerator(PersistentCollectionGenerator $persistentCollectionGenerator) |
||
581 | |||
582 | /** |
||
583 | * Get the persistent collection generator. |
||
584 | * |
||
585 | * @return DefaultPersistentCollectionGenerator |
||
586 | */ |
||
587 | public function getPersistentCollectionGenerator() |
||
597 | } |
||
598 |