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 | public function addDocumentNamespace(string $alias, string $namespace): void |
||
90 | |||
91 | /** |
||
92 | * Resolves a registered namespace alias to the full namespace. |
||
93 | * |
||
94 | * @throws MongoDBException |
||
95 | */ |
||
96 | public function getDocumentNamespace(string $documentNamespaceAlias): string |
||
104 | |||
105 | /** |
||
106 | * Retrieves the list of registered document namespace aliases. |
||
107 | */ |
||
108 | public function getDocumentNamespaces(): array |
||
112 | |||
113 | /** |
||
114 | * Set the document alias map |
||
115 | */ |
||
116 | public function setDocumentNamespaces(array $documentNamespaces): void |
||
120 | |||
121 | /** |
||
122 | * Sets the cache driver implementation that is used for metadata caching. |
||
123 | * |
||
124 | * @todo Force parameter to be a Closure to ensure lazy evaluation |
||
125 | * (as soon as a metadata cache is in effect, the driver never needs to initialize). |
||
126 | */ |
||
127 | 1665 | public function setMetadataDriverImpl(MappingDriver $driverImpl): void |
|
131 | |||
132 | /** |
||
133 | * Add a new default annotation driver with a correctly configured annotation reader. |
||
134 | */ |
||
135 | public function newDefaultAnnotationDriver(array $paths = []): AnnotationDriver |
||
141 | |||
142 | /** |
||
143 | * Gets the cache driver implementation that is used for the mapping metadata. |
||
144 | */ |
||
145 | 1403 | public function getMetadataDriverImpl(): ?MappingDriver |
|
149 | |||
150 | 1602 | public function getMetadataCacheImpl(): ?Cache |
|
154 | |||
155 | public function setMetadataCacheImpl(Cache $cacheImpl): void |
||
159 | |||
160 | /** |
||
161 | * Sets the directory where Doctrine generates any necessary proxy class files. |
||
162 | */ |
||
163 | 1602 | public function setProxyDir(string $dir): void |
|
167 | |||
168 | /** |
||
169 | * Gets the directory where Doctrine generates any necessary proxy class files. |
||
170 | */ |
||
171 | 1602 | public function getProxyDir(): ?string |
|
175 | |||
176 | /** |
||
177 | * Gets an int flag that indicates whether proxy classes should always be regenerated |
||
178 | * during each script execution. |
||
179 | */ |
||
180 | 1602 | public function getAutoGenerateProxyClasses(): int |
|
184 | |||
185 | /** |
||
186 | * Sets an int flag that indicates whether proxy classes should always be regenerated |
||
187 | * during each script execution. |
||
188 | */ |
||
189 | public function setAutoGenerateProxyClasses(int $mode): void |
||
193 | |||
194 | 1602 | public function getProxyNamespace(): ?string |
|
198 | |||
199 | 1602 | public function setProxyNamespace(string $ns): void |
|
203 | |||
204 | 1602 | public function setHydratorDir(string $dir): void |
|
208 | |||
209 | 1602 | public function getHydratorDir(): ?string |
|
213 | |||
214 | /** |
||
215 | * Gets an int flag that indicates whether hydrator classes should always be regenerated |
||
216 | * during each script execution. |
||
217 | */ |
||
218 | 1602 | public function getAutoGenerateHydratorClasses(): int |
|
222 | |||
223 | /** |
||
224 | * Sets an int flag that indicates whether hydrator classes should always be regenerated |
||
225 | * during each script execution. |
||
226 | */ |
||
227 | public function setAutoGenerateHydratorClasses(int $mode): void |
||
231 | |||
232 | 1602 | public function getHydratorNamespace(): ?string |
|
236 | |||
237 | 1602 | public function setHydratorNamespace(string $ns): void |
|
241 | |||
242 | 1602 | public function setPersistentCollectionDir(string $dir): void |
|
246 | |||
247 | 11 | public function getPersistentCollectionDir(): ?string |
|
251 | |||
252 | /** |
||
253 | * Gets a integer flag that indicates how and when persistent collection |
||
254 | * classes should be generated. |
||
255 | */ |
||
256 | 7 | public function getAutoGeneratePersistentCollectionClasses(): int |
|
260 | |||
261 | /** |
||
262 | * Sets a integer flag that indicates how and when persistent collection |
||
263 | * classes should be generated. |
||
264 | */ |
||
265 | public function setAutoGeneratePersistentCollectionClasses(int $mode): void |
||
269 | |||
270 | 11 | public function getPersistentCollectionNamespace(): ?string |
|
274 | |||
275 | 1602 | public function setPersistentCollectionNamespace(string $ns): void |
|
279 | |||
280 | /** |
||
281 | * Sets the default DB to use for all Documents that do not specify |
||
282 | * a database. |
||
283 | */ |
||
284 | 1602 | public function setDefaultDB(string $defaultDB): void |
|
288 | |||
289 | /** |
||
290 | * Gets the default DB to use for all Documents that do not specify a database. |
||
291 | */ |
||
292 | 1263 | public function getDefaultDB(): ?string |
|
296 | |||
297 | public function setClassMetadataFactoryName(string $cmfName): void |
||
301 | |||
302 | 1602 | public function getClassMetadataFactoryName(): string |
|
309 | |||
310 | 554 | public function getDefaultCommitOptions(): array |
|
314 | |||
315 | 1 | public function setDefaultCommitOptions(array $defaultCommitOptions): void |
|
319 | |||
320 | /** |
||
321 | * Add a filter to the list of possible filters. |
||
322 | */ |
||
323 | 1602 | public function addFilter(string $name, string $className, array $parameters = []): void |
|
330 | |||
331 | 24 | public function getFilterClassName(string $name): ?string |
|
337 | |||
338 | 23 | public function getFilterParameters(string $name): ?array |
|
344 | |||
345 | /** |
||
346 | * @throws MongoDBException If not is a ObjectRepository. |
||
347 | */ |
||
348 | public function setDefaultDocumentRepositoryClassName(string $className): void |
||
358 | |||
359 | 319 | public function getDefaultDocumentRepositoryClassName(): string |
|
363 | |||
364 | /** |
||
365 | * @throws MongoDBException If the class does not implement the GridFSRepository interface. |
||
366 | */ |
||
367 | public function setDefaultGridFSRepositoryClassName(string $className): void |
||
377 | |||
378 | 10 | public function getDefaultGridFSRepositoryClassName(): string |
|
382 | |||
383 | 2 | public function setRepositoryFactory(RepositoryFactory $repositoryFactory): void |
|
387 | |||
388 | 1602 | public function getRepositoryFactory(): RepositoryFactory |
|
392 | |||
393 | public function setPersistentCollectionFactory(PersistentCollectionFactory $persistentCollectionFactory): void |
||
397 | |||
398 | 394 | public function getPersistentCollectionFactory(): PersistentCollectionFactory |
|
405 | |||
406 | public function setPersistentCollectionGenerator(PersistentCollectionGenerator $persistentCollectionGenerator): void |
||
410 | |||
411 | 8 | public function getPersistentCollectionGenerator(): PersistentCollectionGenerator |
|
421 | } |
||
422 |