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 |
||
| 42 | class Configuration |
||
| 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 | public const AUTOGENERATE_NEVER = 0; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Always generates a new proxy/hydrator/persistent collection in every request. |
||
| 53 | * |
||
| 54 | * This is only sane during development. |
||
| 55 | * Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
| 56 | */ |
||
| 57 | public const AUTOGENERATE_ALWAYS = 1; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Autogenerate the proxy/hydrator/persistent collection class when the file does not exist. |
||
| 61 | * |
||
| 62 | * This strategy causes a file exists call whenever any proxy/hydrator is used the |
||
| 63 | * first time in a request. Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
| 64 | */ |
||
| 65 | public const AUTOGENERATE_FILE_NOT_EXISTS = 2; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Generate the proxy/hydrator/persistent collection classes using eval(). |
||
| 69 | * |
||
| 70 | * This strategy is only sane for development. |
||
| 71 | * Copied from \Doctrine\Common\Proxy\AbstractProxyFactory. |
||
| 72 | */ |
||
| 73 | public const AUTOGENERATE_EVAL = 3; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Array of attributes for this configuration instance. |
||
| 77 | * |
||
| 78 | * @var array |
||
| 79 | */ |
||
| 80 | private $attributes = []; |
||
| 81 | |||
| 82 | /** @var ProxyManagerConfiguration */ |
||
| 83 | private $proxyManagerConfiguration; |
||
| 84 | |||
| 85 | /** @var int */ |
||
| 86 | private $autoGenerateProxyClasses = self::AUTOGENERATE_EVAL; |
||
| 87 | |||
| 88 | 1832 | public function __construct() |
|
| 89 | { |
||
| 90 | 1832 | $this->proxyManagerConfiguration = new ProxyManagerConfiguration(); |
|
| 91 | 1832 | $this->setAutoGenerateProxyClasses(self::AUTOGENERATE_FILE_NOT_EXISTS); |
|
| 92 | 1832 | } |
|
| 93 | |||
| 94 | /** |
||
| 95 | * Adds a namespace under a certain alias. |
||
| 96 | */ |
||
| 97 | public function addDocumentNamespace(string $alias, string $namespace) : void |
||
| 98 | { |
||
| 99 | $this->attributes['documentNamespaces'][$alias] = $namespace; |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Resolves a registered namespace alias to the full namespace. |
||
| 104 | * |
||
| 105 | * @throws MongoDBException |
||
| 106 | */ |
||
| 107 | public function getDocumentNamespace(string $documentNamespaceAlias) : string |
||
| 108 | { |
||
| 109 | if (! isset($this->attributes['documentNamespaces'][$documentNamespaceAlias])) { |
||
| 110 | throw MongoDBException::unknownDocumentNamespace($documentNamespaceAlias); |
||
| 111 | } |
||
| 112 | |||
| 113 | return trim($this->attributes['documentNamespaces'][$documentNamespaceAlias], '\\'); |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Retrieves the list of registered document namespace aliases. |
||
| 118 | */ |
||
| 119 | public function getDocumentNamespaces() : array |
||
| 120 | { |
||
| 121 | return $this->attributes['documentNamespaces']; |
||
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Set the document alias map |
||
| 126 | */ |
||
| 127 | public function setDocumentNamespaces(array $documentNamespaces) : void |
||
| 128 | { |
||
| 129 | $this->attributes['documentNamespaces'] = $documentNamespaces; |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Sets the cache driver implementation that is used for metadata caching. |
||
| 134 | * |
||
| 135 | * @todo Force parameter to be a Closure to ensure lazy evaluation |
||
| 136 | * (as soon as a metadata cache is in effect, the driver never needs to initialize). |
||
| 137 | */ |
||
| 138 | 1832 | public function setMetadataDriverImpl(MappingDriver $driverImpl) : void |
|
| 142 | |||
| 143 | /** |
||
| 144 | * Add a new default annotation driver with a correctly configured annotation reader. |
||
| 145 | */ |
||
| 146 | public function newDefaultAnnotationDriver(array $paths = []) : AnnotationDriver |
||
| 147 | { |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Gets the cache driver implementation that is used for the mapping metadata. |
||
| 155 | */ |
||
| 156 | 1606 | public function getMetadataDriverImpl() : ?MappingDriver |
|
| 160 | |||
| 161 | 1832 | public function getMetadataCacheImpl() : ?Cache |
|
| 165 | |||
| 166 | public function setMetadataCacheImpl(Cache $cacheImpl) : void |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Sets the directory where Doctrine generates any necessary proxy class files. |
||
| 173 | */ |
||
| 174 | 1832 | public function setProxyDir(string $dir) : void |
|
| 185 | |||
| 186 | /** |
||
| 187 | * Gets the directory where Doctrine generates any necessary proxy class files. |
||
| 188 | */ |
||
| 189 | public function getProxyDir() : ?string |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Gets an int flag that indicates whether proxy classes should always be regenerated |
||
| 196 | * during each script execution. |
||
| 197 | */ |
||
| 198 | public function getAutoGenerateProxyClasses() : int |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Sets an int flag that indicates whether proxy classes should always be regenerated |
||
| 205 | * during each script execution. |
||
| 206 | * |
||
| 207 | * @throws InvalidArgumentException If an invalid mode was given. |
||
| 208 | */ |
||
| 209 | 1832 | public function setAutoGenerateProxyClasses(int $mode) : void |
|
| 229 | |||
| 230 | public function getProxyNamespace() : ?string |
||
| 234 | |||
| 235 | 1832 | public function setProxyNamespace(string $ns) : void |
|
| 239 | |||
| 240 | 1832 | public function setHydratorDir(string $dir) : void |
|
| 244 | |||
| 245 | 1832 | public function getHydratorDir() : ?string |
|
| 249 | |||
| 250 | /** |
||
| 251 | * Gets an int flag that indicates whether hydrator classes should always be regenerated |
||
| 252 | * during each script execution. |
||
| 253 | */ |
||
| 254 | 1832 | public function getAutoGenerateHydratorClasses() : int |
|
| 258 | |||
| 259 | /** |
||
| 260 | * Sets an int flag that indicates whether hydrator classes should always be regenerated |
||
| 261 | * during each script execution. |
||
| 262 | */ |
||
| 263 | public function setAutoGenerateHydratorClasses(int $mode) : void |
||
| 267 | |||
| 268 | 1832 | public function getHydratorNamespace() : ?string |
|
| 272 | |||
| 273 | 1832 | public function setHydratorNamespace(string $ns) : void |
|
| 277 | |||
| 278 | 1832 | public function setPersistentCollectionDir(string $dir) : void |
|
| 282 | |||
| 283 | 11 | public function getPersistentCollectionDir() : ?string |
|
| 287 | |||
| 288 | /** |
||
| 289 | * Gets a integer flag that indicates how and when persistent collection |
||
| 290 | * classes should be generated. |
||
| 291 | */ |
||
| 292 | 7 | public function getAutoGeneratePersistentCollectionClasses() : int |
|
| 296 | |||
| 297 | /** |
||
| 298 | * Sets a integer flag that indicates how and when persistent collection |
||
| 299 | * classes should be generated. |
||
| 300 | */ |
||
| 301 | public function setAutoGeneratePersistentCollectionClasses(int $mode) : void |
||
| 305 | |||
| 306 | 11 | public function getPersistentCollectionNamespace() : ?string |
|
| 310 | |||
| 311 | 1832 | public function setPersistentCollectionNamespace(string $ns) : void |
|
| 315 | |||
| 316 | /** |
||
| 317 | * Sets the default DB to use for all Documents that do not specify |
||
| 318 | * a database. |
||
| 319 | */ |
||
| 320 | 1832 | public function setDefaultDB(string $defaultDB) : void |
|
| 324 | |||
| 325 | /** |
||
| 326 | * Gets the default DB to use for all Documents that do not specify a database. |
||
| 327 | */ |
||
| 328 | 1490 | public function getDefaultDB() : ?string |
|
| 332 | |||
| 333 | public function setClassMetadataFactoryName(string $cmfName) : void |
||
| 337 | |||
| 338 | 1832 | public function getClassMetadataFactoryName() : string |
|
| 346 | |||
| 347 | 618 | public function getDefaultCommitOptions() : array |
|
| 351 | |||
| 352 | 1 | public function setDefaultCommitOptions(array $defaultCommitOptions) : void |
|
| 356 | |||
| 357 | /** |
||
| 358 | * Add a filter to the list of possible filters. |
||
| 359 | */ |
||
| 360 | 1832 | public function addFilter(string $name, string $className, array $parameters = []) : void |
|
| 367 | |||
| 368 | 24 | public function getFilterClassName(string $name) : ?string |
|
| 374 | |||
| 375 | 23 | public function getFilterParameters(string $name) : array |
|
| 381 | |||
| 382 | /** |
||
| 383 | * @throws MongoDBException If not is a ObjectRepository. |
||
| 384 | */ |
||
| 385 | public function setDefaultDocumentRepositoryClassName(string $className) : void |
||
| 395 | |||
| 396 | 360 | public function getDefaultDocumentRepositoryClassName() : string |
|
| 400 | |||
| 401 | /** |
||
| 402 | * @throws MongoDBException If the class does not implement the GridFSRepository interface. |
||
| 403 | */ |
||
| 404 | public function setDefaultGridFSRepositoryClassName(string $className) : void |
||
| 414 | |||
| 415 | 12 | public function getDefaultGridFSRepositoryClassName() : string |
|
| 419 | |||
| 420 | 2 | public function setRepositoryFactory(RepositoryFactory $repositoryFactory) : void |
|
| 424 | |||
| 425 | 1832 | public function getRepositoryFactory() : RepositoryFactory |
|
| 429 | |||
| 430 | public function setPersistentCollectionFactory(PersistentCollectionFactory $persistentCollectionFactory) : void |
||
| 434 | |||
| 435 | 439 | public function getPersistentCollectionFactory() : PersistentCollectionFactory |
|
| 443 | |||
| 444 | public function setPersistentCollectionGenerator(PersistentCollectionGenerator $persistentCollectionGenerator) : void |
||
| 448 | |||
| 449 | 8 | public function getPersistentCollectionGenerator() : PersistentCollectionGenerator |
|
| 468 | |||
| 469 | 1832 | public function buildGhostObjectFactory() : LazyLoadingGhostFactory |
|
| 473 | |||
| 474 | 1832 | public function getProxyManagerConfiguration() : ProxyManagerConfiguration |
|
| 478 | } |
||
| 479 | |||
| 481 |