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 | public function __construct() |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Adds a namespace under a certain alias. |
||
| 95 | */ |
||
| 96 | public function addDocumentNamespace(string $alias, string $namespace) : void |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Resolves a registered namespace alias to the full namespace. |
||
| 103 | * |
||
| 104 | * @throws MongoDBException |
||
| 105 | */ |
||
| 106 | public function getDocumentNamespace(string $documentNamespaceAlias) : string |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Retrieves the list of registered document namespace aliases. |
||
| 117 | */ |
||
| 118 | public function getDocumentNamespaces() : array |
||
| 122 | 1699 | ||
| 123 | /** |
||
| 124 | * Set the document alias map |
||
| 125 | */ |
||
| 126 | public function setDocumentNamespaces(array $documentNamespaces) : void |
||
| 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 | 1434 | public function setMetadataDriverImpl(MappingDriver $driverImpl) : void |
|
| 141 | |||
| 142 | 1636 | /** |
|
| 143 | * Add a new default annotation driver with a correctly configured annotation reader. |
||
| 144 | 1636 | */ |
|
| 145 | public function newDefaultAnnotationDriver(array $paths = []) : AnnotationDriver |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Gets the cache driver implementation that is used for the mapping metadata. |
||
| 154 | */ |
||
| 155 | 1636 | public function getMetadataDriverImpl() : ?MappingDriver |
|
| 159 | |||
| 160 | public function getMetadataCacheImpl() : ?Cache |
||
| 164 | |||
| 165 | 1636 | public function setMetadataCacheImpl(Cache $cacheImpl) : void |
|
| 169 | |||
| 170 | /** |
||
| 171 | * Sets the directory where Doctrine generates any necessary proxy class files. |
||
| 172 | 1636 | */ |
|
| 173 | public function setProxyDir(string $dir) : void |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Gets the directory where Doctrine generates any necessary proxy class files. |
||
| 180 | */ |
||
| 181 | public function getProxyDir() : ?string |
||
| 185 | |||
| 186 | 1636 | /** |
|
| 187 | * Gets an int flag that indicates whether proxy classes should always be regenerated |
||
| 188 | 1636 | * during each script execution. |
|
| 189 | */ |
||
| 190 | public function getAutoGenerateProxyClasses() : int |
||
| 194 | 1636 | ||
| 195 | /** |
||
| 196 | 1636 | * Sets an int flag that indicates whether proxy classes should always be regenerated |
|
| 197 | * during each script execution. |
||
| 198 | 1636 | * |
|
| 199 | 1636 | * @throws InvalidArgumentException If an invalid mode was given. |
|
| 200 | */ |
||
| 201 | 1636 | public function setAutoGenerateProxyClasses(int $mode) : void |
|
| 221 | |||
| 222 | public function getProxyNamespace() : ?string |
||
| 226 | 1636 | ||
| 227 | public function setProxyNamespace(string $ns) : void |
||
| 231 | 1636 | ||
| 232 | 1636 | public function setHydratorDir(string $dir) : void |
|
| 236 | 1636 | ||
| 237 | 1636 | public function getHydratorDir() : ?string |
|
| 241 | 11 | ||
| 242 | /** |
||
| 243 | * Gets an int flag that indicates whether hydrator classes should always be regenerated |
||
| 244 | * during each script execution. |
||
| 245 | */ |
||
| 246 | public function getAutoGenerateHydratorClasses() : int |
||
| 250 | 7 | ||
| 251 | /** |
||
| 252 | * Sets an int flag that indicates whether hydrator classes should always be regenerated |
||
| 253 | * during each script execution. |
||
| 254 | */ |
||
| 255 | public function setAutoGenerateHydratorClasses(int $mode) : void |
||
| 259 | |||
| 260 | public function getHydratorNamespace() : ?string |
||
| 264 | 11 | ||
| 265 | public function setHydratorNamespace(string $ns) : void |
||
| 269 | 1636 | ||
| 270 | 1636 | public function setPersistentCollectionDir(string $dir) : void |
|
| 274 | |||
| 275 | public function getPersistentCollectionDir() : ?string |
||
| 279 | 1636 | ||
| 280 | /** |
||
| 281 | * Gets a integer flag that indicates how and when persistent collection |
||
| 282 | * classes should be generated. |
||
| 283 | */ |
||
| 284 | 1294 | public function getAutoGeneratePersistentCollectionClasses() : int |
|
| 288 | |||
| 289 | /** |
||
| 290 | * Sets a integer flag that indicates how and when persistent collection |
||
| 291 | * classes should be generated. |
||
| 292 | */ |
||
| 293 | public function setAutoGeneratePersistentCollectionClasses(int $mode) : void |
||
| 297 | 1636 | ||
| 298 | public function getPersistentCollectionNamespace() : ?string |
||
| 302 | 584 | ||
| 303 | public function setPersistentCollectionNamespace(string $ns) : void |
||
| 307 | 1 | ||
| 308 | /** |
||
| 309 | 1 | * Sets the default DB to use for all Documents that do not specify |
|
| 310 | 1 | * a database. |
|
| 311 | */ |
||
| 312 | public function setDefaultDB(string $defaultDB) : void |
||
| 316 | |||
| 317 | 1636 | /** |
|
| 318 | 1636 | * Gets the default DB to use for all Documents that do not specify a database. |
|
| 319 | 1636 | */ |
|
| 320 | public function getDefaultDB() : ?string |
||
| 324 | |||
| 325 | 24 | public function setClassMetadataFactoryName(string $cmfName) : void |
|
| 329 | |||
| 330 | 23 | public function getClassMetadataFactoryName() : string |
|
| 337 | |||
| 338 | public function getDefaultCommitOptions() : array |
||
| 342 | |||
| 343 | public function setDefaultCommitOptions(array $defaultCommitOptions) : void |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Add a filter to the list of possible filters. |
||
| 350 | */ |
||
| 351 | 340 | public function addFilter(string $name, string $className, array $parameters = []) : void |
|
| 358 | |||
| 359 | public function getFilterClassName(string $name) : ?string |
||
| 365 | |||
| 366 | public function getFilterParameters(string $name) : ?array |
||
| 372 | 10 | ||
| 373 | /** |
||
| 374 | * @throws MongoDBException If not is a ObjectRepository. |
||
| 375 | 2 | */ |
|
| 376 | public function setDefaultDocumentRepositoryClassName(string $className) : void |
||
| 386 | |||
| 387 | public function getDefaultDocumentRepositoryClassName() : string |
||
| 391 | |||
| 392 | 415 | /** |
|
| 393 | 415 | * @throws MongoDBException If the class does not implement the GridFSRepository interface. |
|
| 394 | */ |
||
| 395 | 415 | public function setDefaultGridFSRepositoryClassName(string $className) : void |
|
| 405 | 8 | ||
| 406 | 8 | public function getDefaultGridFSRepositoryClassName() : string |
|
| 410 | |||
| 411 | 8 | public function setRepositoryFactory(RepositoryFactory $repositoryFactory) : void |
|
| 415 | |||
| 416 | public function getRepositoryFactory() : RepositoryFactory |
||
| 420 | |||
| 421 | public function setPersistentCollectionFactory(PersistentCollectionFactory $persistentCollectionFactory) : void |
||
| 425 | |||
| 426 | public function getPersistentCollectionFactory() : PersistentCollectionFactory |
||
| 433 | |||
| 434 | public function setPersistentCollectionGenerator(PersistentCollectionGenerator $persistentCollectionGenerator) : void |
||
| 438 | |||
| 439 | public function getPersistentCollectionGenerator() : PersistentCollectionGenerator |
||
| 449 | |||
| 450 | public function buildGhostObjectFactory() : LazyLoadingGhostFactory |
||
| 454 | |||
| 455 | public function getProxyManagerConfiguration() : ProxyManagerConfiguration |
||
| 459 | } |
||
| 460 |