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 = 'provided-package'; |
||
25 | const KEY_SUGGESTED_PACKAGE = 'suggested-package'; |
||
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 Configuration |
||
39 | */ |
||
40 | public function fromCommandLine($inputList) |
||
44 | |||
45 | /** |
||
46 | 9 | * @param array $inputList |
|
47 | * |
||
48 | 9 | * @return Configuration |
|
49 | */ |
||
50 | 9 | protected function createConfiguration(array $inputList) |
|
70 | 9 | ||
71 | 9 | /** |
|
72 | 9 | * @param array $inputList |
|
73 | 9 | * @param string $key |
|
74 | 9 | * @param string $defaultValue |
|
75 | 9 | * |
|
76 | 9 | * @return string |
|
77 | 9 | */ |
|
78 | 9 | protected function getValue(array $inputList, $key, $defaultValue) |
|
82 | 9 | ||
83 | 9 | /** |
|
84 | 9 | * @param array $inputList |
|
85 | 9 | * |
|
86 | 9 | * @return array |
|
87 | 9 | */ |
|
88 | 9 | protected function extractKeywords(array $inputList) |
|
99 | 9 | ||
100 | 1 | /** |
|
101 | 1 | * @param array $inputList |
|
102 | 1 | * |
|
103 | 1 | * @return array |
|
104 | */ |
||
105 | 9 | protected function extractAuthors(array $inputList) |
|
121 | 1 | ||
122 | /** |
||
123 | 1 | * @param array $inputList |
|
124 | 1 | * |
|
125 | 1 | * @return array |
|
126 | */ |
||
127 | 9 | protected function extractProvidedPackages(array $inputList) |
|
139 | 2 | ||
140 | 2 | /** |
|
141 | 2 | * @param array $inputList |
|
142 | 2 | * |
|
143 | 2 | * @return array |
|
144 | */ |
||
145 | 9 | protected function extractSuggestedPackages(array $inputList) |
|
162 | 2 | ||
163 | 2 | /** |
|
164 | 2 | * @param array $inputList |
|
165 | 2 | * |
|
166 | 2 | * @return array |
|
167 | */ |
||
168 | 9 | protected function extractSupports(array $inputList) |
|
180 | 2 | ||
181 | 2 | /** |
|
182 | 2 | * @param array $inputList |
|
183 | 2 | * |
|
184 | 2 | * @return array |
|
185 | */ |
||
186 | 9 | protected function extractAutoloads(array $inputList) |
|
201 | 9 | ||
202 | /** |
||
203 | 9 | * @param array $inputList |
|
204 | 9 | * |
|
205 | 9 | * @return array |
|
206 | 9 | */ |
|
207 | protected function extractAutoloadsDev(array $inputList) |
||
221 | 9 | ||
222 | 9 | /** |
|
223 | * @param array $inputList |
||
224 | 9 | * |
|
225 | 9 | * @return array |
|
226 | 9 | */ |
|
227 | 9 | protected function extractRequiredPackages(array $inputList) |
|
239 | 9 | /** |
|
240 | 9 | * @param array $inputList |
|
241 | 2 | * |
|
242 | 2 | * @return array |
|
243 | 2 | */ |
|
244 | 2 | protected function extractRequiredDevPackages(array $inputList) |
|
256 | 9 | ||
257 | 9 | /** |
|
258 | 2 | * @param array $inputList |
|
259 | 2 | * |
|
260 | 2 | * @return array |
|
261 | 2 | */ |
|
262 | 2 | protected function extractScripts(array $inputList) |
|
274 | 9 | ||
275 | 9 | /** |
|
276 | 2 | * @param string $value |
|
277 | 2 | * |
|
278 | 2 | * @return array |
|
279 | 2 | */ |
|
280 | 2 | protected function extractDataFromValue($value) |
|
284 | |||
285 | /** |
||
286 | * @param array $inputList |
||
287 | * @param string $optionKey |
||
288 | * |
||
289 | * @return array |
||
290 | 9 | */ |
|
291 | protected function extractAutoloadList(array $inputList, $optionKey) |
||
303 | } |
||
304 |