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 | /** Arguments */ |
||
| 19 | const ARGUMENT_PACKAGE_NAME = 'package-name'; |
||
| 20 | const ARGUMENT_CONFIGURATION_DEST_FOLDER = 'destination'; |
||
| 21 | |||
| 22 | /** Options */ |
||
| 23 | const OPTION_TYPE = 'type'; |
||
| 24 | const OPTION_LICENSE = 'license'; |
||
| 25 | const OPTION_PACKAGE_VERSION = 'package-version'; |
||
| 26 | const OPTION_DESCRIPTION = 'description'; |
||
| 27 | const OPTION_KEYWORD = 'keyword'; |
||
| 28 | const OPTION_AUTHOR = 'author'; |
||
| 29 | const OPTION_PROVIDED_PACKAGE = 'provided-package'; |
||
| 30 | const OPTION_SUGGESTED_PACKAGE = 'suggested-package'; |
||
| 31 | const OPTION_SUPPORT = 'support'; |
||
| 32 | const OPTION_AUTOLOAD_PSR0 = 'autoload-psr0'; |
||
| 33 | const OPTION_AUTOLOAD_PSR4 = 'autoload-psr4'; |
||
| 34 | const OPTION_AUTOLOAD_DEV_PSR0 = 'autoload-dev-psr0'; |
||
| 35 | const OPTION_AUTOLOAD_DEV_PSR4 = 'autoload-dev-psr4'; |
||
| 36 | const OPTION_REQUIRE = 'require'; |
||
| 37 | const OPTION_REQUIRE_DEV = 'require-dev'; |
||
| 38 | const OPTION_SCRIPT = 'script'; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param array $argumentList |
||
| 42 | * @param array $optionList |
||
| 43 | * |
||
| 44 | * @return WriteConfigurationRequest |
||
| 45 | */ |
||
| 46 | 9 | public function fromCommandLine(array $argumentList, array $optionList) |
|
| 55 | |||
| 56 | /** |
||
| 57 | * @param array $argumentList |
||
| 58 | * @param array $optionList |
||
| 59 | * |
||
| 60 | * @return Configuration |
||
| 61 | */ |
||
| 62 | 9 | protected function createConfiguration(array $argumentList, array $optionList) |
|
| 90 | |||
| 91 | /** |
||
| 92 | * @param array $optionList |
||
| 93 | * |
||
| 94 | * @return array |
||
| 95 | */ |
||
| 96 | 9 | protected function extractKeywords(array $optionList) |
|
| 107 | |||
| 108 | /** |
||
| 109 | * @param array $optionList |
||
| 110 | * |
||
| 111 | * @return array |
||
| 112 | */ |
||
| 113 | 9 | protected function extractAuthors(array $optionList) |
|
| 129 | |||
| 130 | /** |
||
| 131 | * @param array $optionList |
||
| 132 | * |
||
| 133 | * @return array |
||
| 134 | */ |
||
| 135 | 9 | protected function extractProvidedPackages(array $optionList) |
|
| 147 | |||
| 148 | /** |
||
| 149 | * @param array $optionList |
||
| 150 | * |
||
| 151 | * @return array |
||
| 152 | */ |
||
| 153 | 9 | protected function extractSuggestedPackages(array $optionList) |
|
| 170 | |||
| 171 | /** |
||
| 172 | * @param array $optionList |
||
| 173 | * |
||
| 174 | * @return array |
||
| 175 | */ |
||
| 176 | 9 | protected function extractSupports(array $optionList) |
|
| 188 | |||
| 189 | /** |
||
| 190 | * @param array $optionList |
||
| 191 | * |
||
| 192 | * @return array |
||
| 193 | */ |
||
| 194 | 9 | protected function extractAutoloads(array $optionList) |
|
| 210 | |||
| 211 | /** |
||
| 212 | * @param array $optionList |
||
| 213 | * |
||
| 214 | * @return array |
||
| 215 | */ |
||
| 216 | 9 | protected function extractAutoloadsDev(array $optionList) |
|
| 231 | |||
| 232 | /** |
||
| 233 | * @param array $optionList |
||
| 234 | * |
||
| 235 | * @return array |
||
| 236 | */ |
||
| 237 | 9 | protected function extractRequiredPackages(array $optionList) |
|
| 249 | /** |
||
| 250 | * @param array $optionList |
||
| 251 | * |
||
| 252 | * @return array |
||
| 253 | */ |
||
| 254 | 9 | protected function extractRequiredDevPackages(array $optionList) |
|
| 266 | |||
| 267 | /** |
||
| 268 | * @param array $optionList |
||
| 269 | * |
||
| 270 | * @return array |
||
| 271 | */ |
||
| 272 | 9 | protected function extractScripts(array $optionList) |
|
| 284 | |||
| 285 | /** |
||
| 286 | * @param string $value |
||
| 287 | * |
||
| 288 | * @return array |
||
| 289 | */ |
||
| 290 | 9 | protected function extractDataFromValue($value) |
|
| 294 | |||
| 295 | /** |
||
| 296 | * @param array $optionList |
||
| 297 | * @param string $optionKey |
||
| 298 | * |
||
| 299 | * @return AutoloadEntry[] |
||
| 300 | */ |
||
| 301 | 9 | protected function extractAutoloadList(array $optionList, $optionKey) |
|
| 314 | } |
||
| 315 |