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 |
||
40 | 9 | */ |
|
41 | public function fromCommandLine($inputList) |
||
45 | |||
46 | /** |
||
47 | * @param array $inputList |
||
48 | * |
||
49 | * @return ConfigurationFile |
||
50 | 9 | */ |
|
51 | protected function createConfiguration(array $inputList) |
||
95 | 1 | ||
96 | /** |
||
97 | 9 | * @param array $inputList |
|
98 | * @param string $key |
||
99 | * @param string $defaultValue |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | protected function getValue(array $inputList, $key, $defaultValue) |
||
107 | 9 | ||
108 | 9 | /** |
|
109 | 1 | * @param array $inputList |
|
110 | 1 | * |
|
111 | 1 | * @return array |
|
112 | 1 | */ |
|
113 | 1 | protected function extractKeywords(array $inputList) |
|
124 | |||
125 | /** |
||
126 | * @param array $inputList |
||
127 | 9 | * |
|
128 | * @return array |
||
129 | 9 | */ |
|
130 | 9 | protected function extractAuthors(array $inputList) |
|
146 | |||
147 | 9 | /** |
|
148 | 9 | * @param array $inputList |
|
149 | 9 | * |
|
150 | 9 | * @return array |
|
151 | 2 | */ |
|
152 | 2 | protected function extractProvidedPackages(array $inputList) |
|
164 | |||
165 | /** |
||
166 | * @param array $inputList |
||
167 | * |
||
168 | 9 | * @return array |
|
169 | */ |
||
170 | 9 | protected function extractSuggestedPackages(array $inputList) |
|
187 | |||
188 | 9 | /** |
|
189 | * @param array $inputList |
||
190 | 9 | * |
|
191 | 2 | * @return array |
|
192 | 9 | */ |
|
193 | protected function extractSupports(array $inputList) |
||
205 | |||
206 | /** |
||
207 | 9 | * @param array $inputList |
|
208 | * |
||
209 | 9 | * @return array |
|
210 | */ |
||
211 | 9 | protected function extractAutoloads(array $inputList) |
|
226 | |||
227 | 9 | /** |
|
228 | * @param array $inputList |
||
229 | 9 | * |
|
230 | 9 | * @return array |
|
231 | 2 | */ |
|
232 | 2 | protected function extractAutoloadsDev(array $inputList) |
|
246 | 9 | ||
247 | 9 | /** |
|
248 | 2 | * @param array $inputList |
|
249 | 2 | * |
|
250 | 2 | * @return array |
|
251 | 2 | */ |
|
252 | 2 | protected function extractRequiredPackages(array $inputList) |
|
264 | 9 | /** |
|
265 | 9 | * @param array $inputList |
|
266 | 2 | * |
|
267 | 2 | * @return array |
|
268 | 2 | */ |
|
269 | 2 | protected function extractRequiredDevPackages(array $inputList) |
|
281 | |||
282 | 9 | /** |
|
283 | * @param array $inputList |
||
284 | * |
||
285 | * @return array |
||
286 | */ |
||
287 | protected function extractScripts(array $inputList) |
||
299 | 3 | ||
300 | /** |
||
301 | 9 | * @param string $value |
|
302 | * |
||
303 | * @return array |
||
304 | */ |
||
305 | protected function extractDataFromValue($value) |
||
309 | |||
310 | /** |
||
311 | * @param array $inputList |
||
312 | * @param string $optionKey |
||
313 | * |
||
314 | * @return array |
||
315 | */ |
||
316 | protected function extractAutoloadList(array $inputList, $optionKey) |
||
328 | } |
||
329 |