Complex classes like InputTransformer 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 InputTransformer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class InputTransformer |
||
| 15 | { |
||
| 16 | const SEPARATOR = '#'; |
||
| 17 | |||
| 18 | const KEY_PACKAGE_NAME = 'package-name'; |
||
| 19 | const KEY_TYPE = 'type'; |
||
| 20 | const KEY_LICENSE = 'license'; |
||
| 21 | const KEY_PACKAGE_VERSION = 'package-version'; |
||
| 22 | const KEY_DESCRIPTION = 'description'; |
||
| 23 | const KEY_KEYWORD = 'keyword'; |
||
| 24 | const KEY_AUTHOR = 'author'; |
||
| 25 | const KEY_PROVIDED_PACKAGE = 'provided-package'; |
||
| 26 | const KEY_SUGGESTED_PACKAGE = 'suggested-package'; |
||
| 27 | const KEY_SUPPORT = 'support'; |
||
| 28 | const KEY_AUTOLOAD_PSR0 = 'autoload-psr0'; |
||
| 29 | const KEY_AUTOLOAD_PSR4 = 'autoload-psr4'; |
||
| 30 | const KEY_AUTOLOAD_DEV_PSR0 = 'autoload-dev-psr0'; |
||
| 31 | const KEY_AUTOLOAD_DEV_PSR4 = 'autoload-dev-psr4'; |
||
| 32 | const KEY_REQUIRE = 'require'; |
||
| 33 | const KEY_REQUIRE_DEV = 'require-dev'; |
||
| 34 | const KEY_SCRIPT = 'script'; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param $inputList |
||
| 38 | * |
||
| 39 | * @return ConfigurationFile|null |
||
| 40 | */ |
||
| 41 | 9 | public function fromCommandLine($inputList) |
|
| 45 | |||
| 46 | /** |
||
| 47 | * @param array $inputList |
||
| 48 | * |
||
| 49 | * @return ConfigurationFile|null |
||
| 50 | */ |
||
| 51 | 9 | protected function createConfigurationFile(array $inputList) |
|
| 101 | |||
| 102 | /** |
||
| 103 | * @param array $inputList |
||
| 104 | * @param string $key |
||
| 105 | * @param string $defaultValue |
||
| 106 | * |
||
| 107 | * @return string |
||
| 108 | */ |
||
| 109 | 9 | protected function getValue(array $inputList, $key, $defaultValue) |
|
| 113 | |||
| 114 | /** |
||
| 115 | * @param array $inputList |
||
| 116 | * |
||
| 117 | * @return array |
||
| 118 | */ |
||
| 119 | 9 | protected function extractKeywords(array $inputList) |
|
| 130 | |||
| 131 | /** |
||
| 132 | * @param array $inputList |
||
| 133 | * |
||
| 134 | * @return array |
||
| 135 | */ |
||
| 136 | 9 | protected function extractAuthors(array $inputList) |
|
| 152 | |||
| 153 | /** |
||
| 154 | * @param array $inputList |
||
| 155 | * |
||
| 156 | * @return array |
||
| 157 | */ |
||
| 158 | 9 | protected function extractProvidedPackages(array $inputList) |
|
| 170 | |||
| 171 | /** |
||
| 172 | * @param array $inputList |
||
| 173 | * |
||
| 174 | * @return array |
||
| 175 | */ |
||
| 176 | 9 | protected function extractSuggestedPackages(array $inputList) |
|
| 193 | |||
| 194 | /** |
||
| 195 | * @param array $inputList |
||
| 196 | * |
||
| 197 | * @return array |
||
| 198 | */ |
||
| 199 | 9 | protected function extractSupports(array $inputList) |
|
| 211 | |||
| 212 | /** |
||
| 213 | * @param array $inputList |
||
| 214 | * |
||
| 215 | * @return array |
||
| 216 | */ |
||
| 217 | 9 | protected function extractAutoloads(array $inputList) |
|
| 232 | |||
| 233 | /** |
||
| 234 | * @param array $inputList |
||
| 235 | * |
||
| 236 | * @return array |
||
| 237 | */ |
||
| 238 | 9 | protected function extractAutoloadsDev(array $inputList) |
|
| 252 | |||
| 253 | /** |
||
| 254 | * @param array $inputList |
||
| 255 | * |
||
| 256 | * @return array |
||
| 257 | */ |
||
| 258 | 9 | protected function extractRequiredPackages(array $inputList) |
|
| 270 | /** |
||
| 271 | * @param array $inputList |
||
| 272 | * |
||
| 273 | * @return array |
||
| 274 | */ |
||
| 275 | 9 | protected function extractRequiredDevPackages(array $inputList) |
|
| 287 | |||
| 288 | /** |
||
| 289 | * @param array $inputList |
||
| 290 | * |
||
| 291 | * @return array |
||
| 292 | */ |
||
| 293 | 9 | protected function extractScripts(array $inputList) |
|
| 305 | |||
| 306 | /** |
||
| 307 | * @param string $value |
||
| 308 | * |
||
| 309 | * @return array |
||
| 310 | */ |
||
| 311 | 9 | protected function extractDataFromValue($value) |
|
| 315 | |||
| 316 | /** |
||
| 317 | * @param array $inputList |
||
| 318 | * @param string $optionKey |
||
| 319 | * |
||
| 320 | * @return array |
||
| 321 | */ |
||
| 322 | 9 | protected function extractAutoloadList(array $inputList, $optionKey) |
|
| 334 | } |
||
| 335 |