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 |
||
| 13 | class Configuration |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | private $rootDir = ''; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var array |
||
| 22 | */ |
||
| 23 | private $watchDirectories = []; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | private $testsDirectory = ''; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | private $bootstrapPath = ''; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | private $phpunitPath = 'vendor/bin/phpunit'; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var null|EventDispatcher |
||
| 42 | */ |
||
| 43 | private $eventDispatcher; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var null|DatabaseSandbox |
||
| 47 | */ |
||
| 48 | private $databaseSandbox; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | private $memoryLimit = '256M'; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var int |
||
| 57 | */ |
||
| 58 | private $numChunks = 1; |
||
| 59 | |||
| 60 | 2 | public static function createFromXmlFile(string $path) : self |
|
| 138 | |||
| 139 | 1 | public function addListener( |
|
| 158 | |||
| 159 | 9 | public function setRootDir(string $rootDir) : self |
|
| 163 | |||
| 164 | 3 | public function getRootDir() : string |
|
| 168 | |||
| 169 | 4 | public function setWatchDirectories(array $watchDirectories) : self |
|
| 185 | |||
| 186 | 3 | public function getWatchDirectories() : array |
|
| 190 | |||
| 191 | 4 | public function setTestsDirectory(string $testsDirectory) : self |
|
| 195 | |||
| 196 | 2 | public function getTestsDirectory() : string |
|
| 200 | |||
| 201 | 3 | public function setBootstrapPath(string $bootstrapPath) : self |
|
| 205 | |||
| 206 | 2 | public function getBootstrapPath() : string |
|
| 210 | |||
| 211 | 9 | public function setPhpunitPath(string $phpunitPath) : self |
|
| 215 | |||
| 216 | 3 | public function getPhpunitPath() : string |
|
| 220 | |||
| 221 | 1 | public function setDatabaseSandbox(DatabaseSandbox $databaseSandbox) : self |
|
| 227 | |||
| 228 | 3 | public function getDatabaseSandbox() : DatabaseSandbox |
|
| 236 | |||
| 237 | 2 | public function setDatabaseNames(array $databaseNames) : self |
|
| 243 | |||
| 244 | public function setSandboxEnabled(bool $sandboxEnabled) : self |
||
| 250 | |||
| 251 | 1 | public function setMemoryLimit(string $memoryLimit) : self |
|
| 257 | |||
| 258 | 2 | public function getMemoryLimit() : string |
|
| 262 | |||
| 263 | 1 | public function setNumChunks(int $numChunks) : self |
|
| 269 | |||
| 270 | 1 | public function getNumChunks() : int |
|
| 274 | |||
| 275 | 1 | public function setEventDispatcher(EventDispatcher $eventDispatcher) : self |
|
| 281 | |||
| 282 | 2 | public function getEventDispatcher() : EventDispatcher |
|
| 290 | |||
| 291 | public function isSetup() |
||
| 307 | |||
| 308 | 16 | private function setPath(string $name, string $path) : self |
|
| 320 | } |
||
| 321 |