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 |
||
40 | class Configuration |
||
41 | { |
||
42 | /** |
||
43 | * Never autogenerate a proxy/hydrator/persistent collection and rely that |
||
44 | * it was generated by some process before deployment. Copied from |
||
45 | * \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
46 | */ |
||
47 | public const AUTOGENERATE_NEVER = 0; |
||
48 | |||
49 | /** |
||
50 | * Always generates a new proxy/hydrator/persistent collection in every request. |
||
51 | * |
||
52 | * This is only sane during development. |
||
53 | * Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
54 | */ |
||
55 | public const AUTOGENERATE_ALWAYS = 1; |
||
56 | |||
57 | /** |
||
58 | * Autogenerate the proxy/hydrator/persistent collection class when the file does not exist. |
||
59 | * |
||
60 | * This strategy causes a file exists call whenever any proxy/hydrator is used the |
||
61 | * first time in a request. Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
62 | */ |
||
63 | public const AUTOGENERATE_FILE_NOT_EXISTS = 2; |
||
64 | |||
65 | /** |
||
66 | * Generate the proxy/hydrator/persistent collection classes using eval(). |
||
67 | * |
||
68 | * This strategy is only sane for development. |
||
69 | * Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
70 | */ |
||
71 | public const AUTOGENERATE_EVAL = 3; |
||
72 | |||
73 | /** |
||
74 | * Array of attributes for this configuration instance. |
||
75 | * |
||
76 | * @var array |
||
77 | */ |
||
78 | private $attributes = []; |
||
79 | |||
80 | /** @var ProxyManagerConfiguration|null */ |
||
81 | private $proxyManagerConfiguration; |
||
82 | |||
83 | /** @var int */ |
||
84 | private $autoGenerateProxyClasses = self::AUTOGENERATE_EVAL; |
||
85 | |||
86 | /** |
||
87 | * Adds a namespace under a certain alias. |
||
88 | */ |
||
89 | public function addDocumentNamespace(string $alias, string $namespace) : void |
||
93 | |||
94 | /** |
||
95 | * Resolves a registered namespace alias to the full namespace. |
||
96 | * |
||
97 | * @throws MongoDBException |
||
98 | */ |
||
99 | public function getDocumentNamespace(string $documentNamespaceAlias) : string |
||
107 | |||
108 | /** |
||
109 | * Retrieves the list of registered document namespace aliases. |
||
110 | */ |
||
111 | public function getDocumentNamespaces() : array |
||
115 | |||
116 | /** |
||
117 | * Set the document alias map |
||
118 | */ |
||
119 | public function setDocumentNamespaces(array $documentNamespaces) : void |
||
123 | |||
124 | /** |
||
125 | * Sets the cache driver implementation that is used for metadata caching. |
||
126 | * |
||
127 | * @todo Force parameter to be a Closure to ensure lazy evaluation |
||
128 | * (as soon as a metadata cache is in effect, the driver never needs to initialize). |
||
129 | */ |
||
130 | 1697 | public function setMetadataDriverImpl(MappingDriver $driverImpl) : void |
|
134 | |||
135 | /** |
||
136 | * Add a new default annotation driver with a correctly configured annotation reader. |
||
137 | */ |
||
138 | public function newDefaultAnnotationDriver(array $paths = []) : AnnotationDriver |
||
144 | |||
145 | /** |
||
146 | * Gets the cache driver implementation that is used for the mapping metadata. |
||
147 | */ |
||
148 | 1432 | public function getMetadataDriverImpl() : ?MappingDriver |
|
152 | |||
153 | 1634 | public function getMetadataCacheImpl() : ?Cache |
|
157 | |||
158 | public function setMetadataCacheImpl(Cache $cacheImpl) : void |
||
162 | |||
163 | /** |
||
164 | * Sets the directory where Doctrine generates any necessary proxy class files. |
||
165 | */ |
||
166 | 1634 | public function setProxyDir(string $dir) : void |
|
171 | |||
172 | /** |
||
173 | * Gets the directory where Doctrine generates any necessary proxy class files. |
||
174 | */ |
||
175 | public function getProxyDir() : ?string |
||
179 | |||
180 | /** |
||
181 | * Gets an int flag that indicates whether proxy classes should always be regenerated |
||
182 | * during each script execution. |
||
183 | */ |
||
184 | public function getAutoGenerateProxyClasses() : int |
||
188 | |||
189 | /** |
||
190 | * Sets an int flag that indicates whether proxy classes should always be regenerated |
||
191 | * during each script execution. |
||
192 | */ |
||
193 | 1634 | public function setAutoGenerateProxyClasses(int $mode) : void |
|
214 | |||
215 | public function getProxyNamespace() : ?string |
||
219 | |||
220 | 1634 | public function setProxyNamespace(string $ns) : void |
|
224 | |||
225 | 1634 | public function setHydratorDir(string $dir) : void |
|
229 | |||
230 | 1634 | public function getHydratorDir() : ?string |
|
234 | |||
235 | /** |
||
236 | * Gets an int flag that indicates whether hydrator classes should always be regenerated |
||
237 | * during each script execution. |
||
238 | */ |
||
239 | 1634 | public function getAutoGenerateHydratorClasses() : int |
|
243 | |||
244 | /** |
||
245 | * Sets an int flag that indicates whether hydrator classes should always be regenerated |
||
246 | * during each script execution. |
||
247 | */ |
||
248 | public function setAutoGenerateHydratorClasses(int $mode) : void |
||
252 | |||
253 | 1634 | public function getHydratorNamespace() : ?string |
|
257 | |||
258 | 1634 | public function setHydratorNamespace(string $ns) : void |
|
262 | |||
263 | 1634 | public function setPersistentCollectionDir(string $dir) : void |
|
267 | |||
268 | 11 | public function getPersistentCollectionDir() : ?string |
|
272 | |||
273 | /** |
||
274 | * Gets a integer flag that indicates how and when persistent collection |
||
275 | * classes should be generated. |
||
276 | */ |
||
277 | 7 | public function getAutoGeneratePersistentCollectionClasses() : int |
|
281 | |||
282 | /** |
||
283 | * Sets a integer flag that indicates how and when persistent collection |
||
284 | * classes should be generated. |
||
285 | */ |
||
286 | public function setAutoGeneratePersistentCollectionClasses(int $mode) : void |
||
290 | |||
291 | 11 | public function getPersistentCollectionNamespace() : ?string |
|
295 | |||
296 | 1634 | public function setPersistentCollectionNamespace(string $ns) : void |
|
300 | |||
301 | /** |
||
302 | * Sets the default DB to use for all Documents that do not specify |
||
303 | * a database. |
||
304 | */ |
||
305 | 1634 | public function setDefaultDB(string $defaultDB) : void |
|
309 | |||
310 | /** |
||
311 | * Gets the default DB to use for all Documents that do not specify a database. |
||
312 | */ |
||
313 | 1293 | public function getDefaultDB() : ?string |
|
317 | |||
318 | public function setClassMetadataFactoryName(string $cmfName) : void |
||
322 | |||
323 | 1634 | public function getClassMetadataFactoryName() : string |
|
330 | |||
331 | 583 | public function getDefaultCommitOptions() : array |
|
335 | |||
336 | 1 | public function setDefaultCommitOptions(array $defaultCommitOptions) : void |
|
340 | |||
341 | /** |
||
342 | * Add a filter to the list of possible filters. |
||
343 | */ |
||
344 | 1634 | public function addFilter(string $name, string $className, array $parameters = []) : void |
|
351 | |||
352 | 24 | public function getFilterClassName(string $name) : ?string |
|
358 | |||
359 | 23 | public function getFilterParameters(string $name) : ?array |
|
365 | |||
366 | /** |
||
367 | * @throws MongoDBException If not is a ObjectRepository. |
||
368 | */ |
||
369 | public function setDefaultDocumentRepositoryClassName(string $className) : void |
||
379 | |||
380 | 339 | public function getDefaultDocumentRepositoryClassName() : string |
|
384 | |||
385 | /** |
||
386 | * @throws MongoDBException If the class does not implement the GridFSRepository interface. |
||
387 | */ |
||
388 | public function setDefaultGridFSRepositoryClassName(string $className) : void |
||
398 | |||
399 | 10 | public function getDefaultGridFSRepositoryClassName() : string |
|
403 | |||
404 | 2 | public function setRepositoryFactory(RepositoryFactory $repositoryFactory) : void |
|
408 | |||
409 | 1634 | public function getRepositoryFactory() : RepositoryFactory |
|
413 | |||
414 | public function setPersistentCollectionFactory(PersistentCollectionFactory $persistentCollectionFactory) : void |
||
418 | |||
419 | 414 | public function getPersistentCollectionFactory() : PersistentCollectionFactory |
|
426 | |||
427 | public function setPersistentCollectionGenerator(PersistentCollectionGenerator $persistentCollectionGenerator) : void |
||
431 | |||
432 | 8 | public function getPersistentCollectionGenerator() : PersistentCollectionGenerator |
|
442 | |||
443 | 1634 | public function buildGhostObjectFactory() : LazyLoadingGhostFactory |
|
447 | |||
448 | 1634 | public function getProxyManagerConfiguration() : ProxyManagerConfiguration |
|
453 | } |
||
454 |