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 |
||
13 | class InputTransformer |
||
14 | { |
||
15 | const SEPARATOR = '#'; |
||
16 | |||
17 | const KEY_PACKAGE_NAME = 'package-name'; |
||
18 | const KEY_TYPE = 'type'; |
||
19 | const KEY_LICENSE = 'license'; |
||
20 | const KEY_PACKAGE_VERSION = 'package-version'; |
||
21 | const KEY_DESCRIPTION = 'description'; |
||
22 | const KEY_KEYWORD = 'keyword'; |
||
23 | const KEY_AUTHOR = 'author'; |
||
24 | const KEY_PROVIDED_PACKAGE = 'provide'; |
||
25 | const KEY_SUGGESTED_PACKAGE = 'suggest'; |
||
26 | const KEY_SUPPORT = 'support'; |
||
27 | const KEY_AUTOLOAD_PSR0 = 'autoload-psr0'; |
||
28 | const KEY_AUTOLOAD_PSR4 = 'autoload-psr4'; |
||
29 | const KEY_AUTOLOAD_DEV_PSR0 = 'autoload-dev-psr0'; |
||
30 | const KEY_AUTOLOAD_DEV_PSR4 = 'autoload-dev-psr4'; |
||
31 | const KEY_REQUIRE = 'require'; |
||
32 | const KEY_REQUIRE_DEV = 'require-dev'; |
||
33 | const KEY_SCRIPT = 'script'; |
||
34 | |||
35 | /** |
||
36 | * @param $inputList |
||
37 | * |
||
38 | * @return ConfigurationFile|null |
||
39 | */ |
||
40 | 10 | public function fromCommandLine($inputList) |
|
44 | |||
45 | /** |
||
46 | * @param array $inputList |
||
47 | * |
||
48 | * @return ConfigurationFile|null |
||
49 | */ |
||
50 | 10 | protected function createConfigurationFile(array $inputList) |
|
122 | |||
123 | /** |
||
124 | * @param array $inputList |
||
125 | * @param string $key |
||
126 | * @param string $defaultValue |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | 9 | protected function getValue(array $inputList, $key, $defaultValue) |
|
134 | |||
135 | /** |
||
136 | * @param array $inputList |
||
137 | * |
||
138 | * @return array |
||
139 | */ |
||
140 | 9 | protected function extractKeywords(array $inputList) |
|
151 | |||
152 | /** |
||
153 | * @param array $inputList |
||
154 | * |
||
155 | * @return array |
||
156 | */ |
||
157 | 9 | protected function extractAuthors(array $inputList) |
|
173 | |||
174 | /** |
||
175 | * @param array $inputList |
||
176 | * |
||
177 | * @return array |
||
178 | */ |
||
179 | 9 | protected function extractProvidedPackages(array $inputList) |
|
191 | |||
192 | /** |
||
193 | * @param array $inputList |
||
194 | * |
||
195 | * @return array |
||
196 | */ |
||
197 | 9 | protected function extractSuggestedPackages(array $inputList) |
|
214 | |||
215 | /** |
||
216 | * @param array $inputList |
||
217 | * |
||
218 | * @return array |
||
219 | */ |
||
220 | 9 | protected function extractSupports(array $inputList) |
|
232 | |||
233 | /** |
||
234 | * @param array $inputList |
||
235 | * |
||
236 | * @return array |
||
237 | */ |
||
238 | 9 | protected function extractAutoloads(array $inputList) |
|
253 | |||
254 | /** |
||
255 | * @param array $inputList |
||
256 | * |
||
257 | * @return array |
||
258 | */ |
||
259 | 9 | protected function extractAutoloadsDev(array $inputList) |
|
273 | |||
274 | /** |
||
275 | * @param array $inputList |
||
276 | * |
||
277 | * @return array |
||
278 | */ |
||
279 | 9 | protected function extractRequiredPackages(array $inputList) |
|
291 | /** |
||
292 | * @param array $inputList |
||
293 | * |
||
294 | * @return array |
||
295 | */ |
||
296 | 9 | protected function extractRequiredDevPackages(array $inputList) |
|
308 | |||
309 | /** |
||
310 | * @param array $inputList |
||
311 | * |
||
312 | * @return array |
||
313 | */ |
||
314 | 9 | protected function extractScripts(array $inputList) |
|
326 | |||
327 | /** |
||
328 | * @param string $value |
||
329 | * |
||
330 | * @return array |
||
331 | */ |
||
332 | 9 | protected function extractDataFromValue($value) |
|
336 | |||
337 | /** |
||
338 | * @param array $inputList |
||
339 | * @param string $optionKey |
||
340 | * |
||
341 | * @return array |
||
342 | */ |
||
343 | 9 | protected function extractAutoloadList(array $inputList, $optionKey) |
|
355 | } |
||
356 |