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 createConfiguration(array $inputList) |
|
97 | |||
98 | /** |
||
99 | * @param array $inputList |
||
100 | * @param string $key |
||
101 | * @param string $defaultValue |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | 9 | protected function getValue(array $inputList, $key, $defaultValue) |
|
109 | |||
110 | /** |
||
111 | * @param array $inputList |
||
112 | * |
||
113 | * @return array |
||
114 | */ |
||
115 | 9 | protected function extractKeywords(array $inputList) |
|
126 | |||
127 | /** |
||
128 | * @param array $inputList |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | 9 | protected function extractAuthors(array $inputList) |
|
148 | |||
149 | /** |
||
150 | * @param array $inputList |
||
151 | * |
||
152 | * @return array |
||
153 | */ |
||
154 | 9 | protected function extractProvidedPackages(array $inputList) |
|
166 | |||
167 | /** |
||
168 | * @param array $inputList |
||
169 | * |
||
170 | * @return array |
||
171 | */ |
||
172 | 9 | protected function extractSuggestedPackages(array $inputList) |
|
189 | |||
190 | /** |
||
191 | * @param array $inputList |
||
192 | * |
||
193 | * @return array |
||
194 | */ |
||
195 | 9 | protected function extractSupports(array $inputList) |
|
207 | |||
208 | /** |
||
209 | * @param array $inputList |
||
210 | * |
||
211 | * @return array |
||
212 | */ |
||
213 | 9 | protected function extractAutoloads(array $inputList) |
|
228 | |||
229 | /** |
||
230 | * @param array $inputList |
||
231 | * |
||
232 | * @return array |
||
233 | */ |
||
234 | 9 | protected function extractAutoloadsDev(array $inputList) |
|
248 | |||
249 | /** |
||
250 | * @param array $inputList |
||
251 | * |
||
252 | * @return array |
||
253 | */ |
||
254 | 9 | protected function extractRequiredPackages(array $inputList) |
|
266 | /** |
||
267 | * @param array $inputList |
||
268 | * |
||
269 | * @return array |
||
270 | */ |
||
271 | 9 | protected function extractRequiredDevPackages(array $inputList) |
|
283 | |||
284 | /** |
||
285 | * @param array $inputList |
||
286 | * |
||
287 | * @return array |
||
288 | */ |
||
289 | 9 | protected function extractScripts(array $inputList) |
|
301 | |||
302 | /** |
||
303 | * @param string $value |
||
304 | * |
||
305 | * @return array |
||
306 | */ |
||
307 | 9 | protected function extractDataFromValue($value) |
|
311 | |||
312 | /** |
||
313 | * @param array $inputList |
||
314 | * @param string $optionKey |
||
315 | * |
||
316 | * @return array |
||
317 | */ |
||
318 | 9 | protected function extractAutoloadList(array $inputList, $optionKey) |
|
330 | } |
||
331 |