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 |
||
41 | class Configuration |
||
42 | { |
||
43 | /** |
||
44 | * Never autogenerate a proxy/hydrator/persistent collection and rely that |
||
45 | * it was generated by some process before deployment. Copied from |
||
46 | * \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
47 | */ |
||
48 | public const AUTOGENERATE_NEVER = 0; |
||
49 | |||
50 | /** |
||
51 | * Always generates a new proxy/hydrator/persistent collection in every request. |
||
52 | * |
||
53 | * This is only sane during development. |
||
54 | * Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
55 | */ |
||
56 | public const AUTOGENERATE_ALWAYS = 1; |
||
57 | |||
58 | /** |
||
59 | * Autogenerate the proxy/hydrator/persistent collection class when the file does not exist. |
||
60 | * |
||
61 | * This strategy causes a file exists call whenever any proxy/hydrator is used the |
||
62 | * first time in a request. Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
63 | */ |
||
64 | public const AUTOGENERATE_FILE_NOT_EXISTS = 2; |
||
65 | |||
66 | /** |
||
67 | * Generate the proxy/hydrator/persistent collection classes using eval(). |
||
68 | * |
||
69 | * This strategy is only sane for development. |
||
70 | * Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
71 | */ |
||
72 | public const AUTOGENERATE_EVAL = 3; |
||
73 | |||
74 | /** |
||
75 | * Array of attributes for this configuration instance. |
||
76 | * |
||
77 | * @var array |
||
78 | */ |
||
79 | private $attributes = []; |
||
80 | |||
81 | /** @var ProxyManagerConfiguration|null */ |
||
82 | private $proxyManagerConfiguration; |
||
83 | |||
84 | /** @var int */ |
||
85 | private $autoGenerateProxyClasses = self::AUTOGENERATE_EVAL; |
||
86 | |||
87 | 1697 | public function __construct() |
|
88 | { |
||
89 | 1697 | $this->proxyManagerConfiguration = new ProxyManagerConfiguration(); |
|
90 | 1697 | $this->setAutoGenerateProxyClasses(self::AUTOGENERATE_FILE_NOT_EXISTS); |
|
91 | 1697 | } |
|
92 | |||
93 | /** |
||
94 | * Adds a namespace under a certain alias. |
||
95 | */ |
||
96 | public function addDocumentNamespace(string $alias, string $namespace) : void |
||
97 | { |
||
98 | $this->attributes['documentNamespaces'][$alias] = $namespace; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Resolves a registered namespace alias to the full namespace. |
||
103 | * |
||
104 | * @throws MongoDBException |
||
105 | */ |
||
106 | public function getDocumentNamespace(string $documentNamespaceAlias) : string |
||
107 | { |
||
108 | if (! isset($this->attributes['documentNamespaces'][$documentNamespaceAlias])) { |
||
109 | throw MongoDBException::unknownDocumentNamespace($documentNamespaceAlias); |
||
110 | } |
||
111 | |||
112 | return trim($this->attributes['documentNamespaces'][$documentNamespaceAlias], '\\'); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Retrieves the list of registered document namespace aliases. |
||
117 | */ |
||
118 | public function getDocumentNamespaces() : array |
||
119 | { |
||
120 | return $this->attributes['documentNamespaces']; |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * Set the document alias map |
||
125 | */ |
||
126 | public function setDocumentNamespaces(array $documentNamespaces) : void |
||
127 | { |
||
128 | $this->attributes['documentNamespaces'] = $documentNamespaces; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Sets the cache driver implementation that is used for metadata caching. |
||
133 | * |
||
134 | * @todo Force parameter to be a Closure to ensure lazy evaluation |
||
135 | * (as soon as a metadata cache is in effect, the driver never needs to initialize). |
||
136 | */ |
||
137 | 1697 | public function setMetadataDriverImpl(MappingDriver $driverImpl) : void |
|
138 | { |
||
139 | 1697 | $this->attributes['metadataDriverImpl'] = $driverImpl; |
|
140 | 1697 | } |
|
141 | |||
142 | /** |
||
143 | * Add a new default annotation driver with a correctly configured annotation reader. |
||
144 | */ |
||
145 | public function newDefaultAnnotationDriver(array $paths = []) : AnnotationDriver |
||
151 | |||
152 | /** |
||
153 | * Gets the cache driver implementation that is used for the mapping metadata. |
||
154 | */ |
||
155 | 1432 | public function getMetadataDriverImpl() : ?MappingDriver |
|
156 | { |
||
157 | 1432 | return $this->attributes['metadataDriverImpl'] ?? null; |
|
159 | |||
160 | 1634 | public function getMetadataCacheImpl() : ?Cache |
|
164 | |||
165 | public function setMetadataCacheImpl(Cache $cacheImpl) : void |
||
169 | |||
170 | /** |
||
171 | * Sets the directory where Doctrine generates any necessary proxy class files. |
||
172 | */ |
||
173 | 1634 | public function setProxyDir(string $dir) : void |
|
184 | |||
185 | /** |
||
186 | * Gets the directory where Doctrine generates any necessary proxy class files. |
||
187 | */ |
||
188 | public function getProxyDir() : ?string |
||
192 | |||
193 | /** |
||
194 | * Gets an int flag that indicates whether proxy classes should always be regenerated |
||
195 | * during each script execution. |
||
196 | */ |
||
197 | public function getAutoGenerateProxyClasses() : int |
||
201 | |||
202 | /** |
||
203 | * Sets an int flag that indicates whether proxy classes should always be regenerated |
||
204 | * during each script execution. |
||
205 | * |
||
206 | * @throws InvalidArgumentException If an invalid mode was given. |
||
207 | */ |
||
208 | 1697 | public function setAutoGenerateProxyClasses(int $mode) : void |
|
228 | |||
229 | public function getProxyNamespace() : ?string |
||
233 | |||
234 | 1634 | public function setProxyNamespace(string $ns) : void |
|
238 | |||
239 | 1634 | public function setHydratorDir(string $dir) : void |
|
243 | |||
244 | 1634 | public function getHydratorDir() : ?string |
|
248 | |||
249 | /** |
||
250 | * Gets an int flag that indicates whether hydrator classes should always be regenerated |
||
251 | * during each script execution. |
||
252 | */ |
||
253 | 1634 | public function getAutoGenerateHydratorClasses() : int |
|
257 | |||
258 | /** |
||
259 | * Sets an int flag that indicates whether hydrator classes should always be regenerated |
||
260 | * during each script execution. |
||
261 | */ |
||
262 | public function setAutoGenerateHydratorClasses(int $mode) : void |
||
266 | |||
267 | 1634 | public function getHydratorNamespace() : ?string |
|
271 | |||
272 | 1634 | public function setHydratorNamespace(string $ns) : void |
|
276 | |||
277 | 1634 | public function setPersistentCollectionDir(string $dir) : void |
|
281 | |||
282 | 11 | public function getPersistentCollectionDir() : ?string |
|
286 | |||
287 | /** |
||
288 | * Gets a integer flag that indicates how and when persistent collection |
||
289 | * classes should be generated. |
||
290 | */ |
||
291 | 7 | public function getAutoGeneratePersistentCollectionClasses() : int |
|
295 | |||
296 | /** |
||
297 | * Sets a integer flag that indicates how and when persistent collection |
||
298 | * classes should be generated. |
||
299 | */ |
||
300 | public function setAutoGeneratePersistentCollectionClasses(int $mode) : void |
||
304 | |||
305 | 11 | public function getPersistentCollectionNamespace() : ?string |
|
309 | |||
310 | 1634 | public function setPersistentCollectionNamespace(string $ns) : void |
|
314 | |||
315 | /** |
||
316 | * Sets the default DB to use for all Documents that do not specify |
||
317 | * a database. |
||
318 | */ |
||
319 | 1634 | public function setDefaultDB(string $defaultDB) : void |
|
323 | |||
324 | /** |
||
325 | * Gets the default DB to use for all Documents that do not specify a database. |
||
326 | */ |
||
327 | 1293 | public function getDefaultDB() : ?string |
|
331 | |||
332 | public function setClassMetadataFactoryName(string $cmfName) : void |
||
336 | |||
337 | 1634 | public function getClassMetadataFactoryName() : string |
|
344 | |||
345 | 583 | public function getDefaultCommitOptions() : array |
|
349 | |||
350 | 1 | public function setDefaultCommitOptions(array $defaultCommitOptions) : void |
|
354 | |||
355 | /** |
||
356 | * Add a filter to the list of possible filters. |
||
357 | */ |
||
358 | 1634 | public function addFilter(string $name, string $className, array $parameters = []) : void |
|
365 | |||
366 | 24 | public function getFilterClassName(string $name) : ?string |
|
372 | |||
373 | 23 | public function getFilterParameters(string $name) : ?array |
|
379 | |||
380 | /** |
||
381 | * @throws MongoDBException If not is a ObjectRepository. |
||
382 | */ |
||
383 | public function setDefaultDocumentRepositoryClassName(string $className) : void |
||
393 | |||
394 | 339 | public function getDefaultDocumentRepositoryClassName() : string |
|
398 | |||
399 | /** |
||
400 | * @throws MongoDBException If the class does not implement the GridFSRepository interface. |
||
401 | */ |
||
402 | public function setDefaultGridFSRepositoryClassName(string $className) : void |
||
412 | |||
413 | 10 | public function getDefaultGridFSRepositoryClassName() : string |
|
417 | |||
418 | 2 | public function setRepositoryFactory(RepositoryFactory $repositoryFactory) : void |
|
422 | |||
423 | 1634 | public function getRepositoryFactory() : RepositoryFactory |
|
427 | |||
428 | public function setPersistentCollectionFactory(PersistentCollectionFactory $persistentCollectionFactory) : void |
||
432 | |||
433 | 414 | public function getPersistentCollectionFactory() : PersistentCollectionFactory |
|
440 | |||
441 | public function setPersistentCollectionGenerator(PersistentCollectionGenerator $persistentCollectionGenerator) : void |
||
445 | |||
446 | 8 | public function getPersistentCollectionGenerator() : PersistentCollectionGenerator |
|
456 | |||
457 | 1634 | public function buildGhostObjectFactory() : LazyLoadingGhostFactory |
|
461 | |||
462 | 1697 | public function getProxyManagerConfiguration() : ProxyManagerConfiguration |
|
466 | } |
||
467 |