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 |
|
182 | |||
183 | /** |
||
184 | * Gets the directory where Doctrine generates any necessary proxy class files. |
||
185 | */ |
||
186 | public function getProxyDir() : ?string |
||
190 | |||
191 | /** |
||
192 | * Gets an int flag that indicates whether proxy classes should always be regenerated |
||
193 | * during each script execution. |
||
194 | */ |
||
195 | public function getAutoGenerateProxyClasses() : int |
||
199 | |||
200 | /** |
||
201 | * Sets an int flag that indicates whether proxy classes should always be regenerated |
||
202 | * during each script execution. |
||
203 | * |
||
204 | * @throws InvalidArgumentException If an invalid mode was given. |
||
205 | */ |
||
206 | 1697 | public function setAutoGenerateProxyClasses(int $mode) : void |
|
226 | |||
227 | public function getProxyNamespace() : ?string |
||
231 | |||
232 | 1634 | public function setProxyNamespace(string $ns) : void |
|
236 | |||
237 | 1634 | public function setHydratorDir(string $dir) : void |
|
241 | |||
242 | 1634 | public function getHydratorDir() : ?string |
|
246 | |||
247 | /** |
||
248 | * Gets an int flag that indicates whether hydrator classes should always be regenerated |
||
249 | * during each script execution. |
||
250 | */ |
||
251 | 1634 | public function getAutoGenerateHydratorClasses() : int |
|
255 | |||
256 | /** |
||
257 | * Sets an int flag that indicates whether hydrator classes should always be regenerated |
||
258 | * during each script execution. |
||
259 | */ |
||
260 | public function setAutoGenerateHydratorClasses(int $mode) : void |
||
264 | |||
265 | 1634 | public function getHydratorNamespace() : ?string |
|
269 | |||
270 | 1634 | public function setHydratorNamespace(string $ns) : void |
|
274 | |||
275 | 1634 | public function setPersistentCollectionDir(string $dir) : void |
|
279 | |||
280 | 11 | public function getPersistentCollectionDir() : ?string |
|
284 | |||
285 | /** |
||
286 | * Gets a integer flag that indicates how and when persistent collection |
||
287 | * classes should be generated. |
||
288 | */ |
||
289 | 7 | public function getAutoGeneratePersistentCollectionClasses() : int |
|
293 | |||
294 | /** |
||
295 | * Sets a integer flag that indicates how and when persistent collection |
||
296 | * classes should be generated. |
||
297 | */ |
||
298 | public function setAutoGeneratePersistentCollectionClasses(int $mode) : void |
||
302 | |||
303 | 11 | public function getPersistentCollectionNamespace() : ?string |
|
307 | |||
308 | 1634 | public function setPersistentCollectionNamespace(string $ns) : void |
|
312 | |||
313 | /** |
||
314 | * Sets the default DB to use for all Documents that do not specify |
||
315 | * a database. |
||
316 | */ |
||
317 | 1634 | public function setDefaultDB(string $defaultDB) : void |
|
321 | |||
322 | /** |
||
323 | * Gets the default DB to use for all Documents that do not specify a database. |
||
324 | */ |
||
325 | 1293 | public function getDefaultDB() : ?string |
|
329 | |||
330 | public function setClassMetadataFactoryName(string $cmfName) : void |
||
334 | |||
335 | 1634 | public function getClassMetadataFactoryName() : string |
|
342 | |||
343 | 583 | public function getDefaultCommitOptions() : array |
|
347 | |||
348 | 1 | public function setDefaultCommitOptions(array $defaultCommitOptions) : void |
|
352 | |||
353 | /** |
||
354 | * Add a filter to the list of possible filters. |
||
355 | */ |
||
356 | 1634 | public function addFilter(string $name, string $className, array $parameters = []) : void |
|
363 | |||
364 | 24 | public function getFilterClassName(string $name) : ?string |
|
370 | |||
371 | 23 | public function getFilterParameters(string $name) : ?array |
|
377 | |||
378 | /** |
||
379 | * @throws MongoDBException If not is a ObjectRepository. |
||
380 | */ |
||
381 | public function setDefaultDocumentRepositoryClassName(string $className) : void |
||
391 | |||
392 | 339 | public function getDefaultDocumentRepositoryClassName() : string |
|
396 | |||
397 | /** |
||
398 | * @throws MongoDBException If the class does not implement the GridFSRepository interface. |
||
399 | */ |
||
400 | public function setDefaultGridFSRepositoryClassName(string $className) : void |
||
410 | |||
411 | 10 | public function getDefaultGridFSRepositoryClassName() : string |
|
415 | |||
416 | 2 | public function setRepositoryFactory(RepositoryFactory $repositoryFactory) : void |
|
420 | |||
421 | 1634 | public function getRepositoryFactory() : RepositoryFactory |
|
425 | |||
426 | public function setPersistentCollectionFactory(PersistentCollectionFactory $persistentCollectionFactory) : void |
||
430 | |||
431 | 414 | public function getPersistentCollectionFactory() : PersistentCollectionFactory |
|
438 | |||
439 | public function setPersistentCollectionGenerator(PersistentCollectionGenerator $persistentCollectionGenerator) : void |
||
443 | |||
444 | 8 | public function getPersistentCollectionGenerator() : PersistentCollectionGenerator |
|
454 | |||
455 | 1634 | public function buildGhostObjectFactory() : LazyLoadingGhostFactory |
|
459 | |||
460 | 1697 | public function getProxyManagerConfiguration() : ProxyManagerConfiguration |
|
464 | } |
||
465 |