Complex classes like ConfigCommand 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 ConfigCommand, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | class ConfigCommand extends AbstractCommand implements IAggregatorAwareCommand |
||
27 | { |
||
28 | |||
29 | /** |
||
30 | * Editor. |
||
31 | * |
||
32 | * @var InteractiveEditor |
||
33 | */ |
||
34 | private $_editor; |
||
35 | |||
36 | /** |
||
37 | * Config editor. |
||
38 | * |
||
39 | * @var ConfigEditor |
||
40 | */ |
||
41 | private $_configEditor; |
||
42 | |||
43 | /** |
||
44 | * Config settings. |
||
45 | * |
||
46 | * @var AbstractConfigSetting[] |
||
47 | */ |
||
48 | protected $configSettings = array(); |
||
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | protected function configure() |
||
91 | |||
92 | /** |
||
93 | * Prepare dependencies. |
||
94 | * |
||
95 | * @return void |
||
96 | */ |
||
97 | protected function prepareDependencies() |
||
107 | |||
108 | /** |
||
109 | * Return possible values for the named option |
||
110 | * |
||
111 | * @param string $optionName Option name. |
||
112 | * @param CompletionContext $context Completion context. |
||
113 | * |
||
114 | * @return array |
||
115 | */ |
||
116 | public function completeOptionValues($optionName, CompletionContext $context) |
||
126 | |||
127 | /** |
||
128 | * {@inheritdoc} |
||
129 | */ |
||
130 | protected function execute(InputInterface $input, OutputInterface $output) |
||
138 | |||
139 | /** |
||
140 | * Shows setting value. |
||
141 | * |
||
142 | * @return boolean |
||
143 | */ |
||
144 | protected function processShow() |
||
156 | |||
157 | /** |
||
158 | * Changes setting value. |
||
159 | * |
||
160 | * @return boolean |
||
161 | */ |
||
162 | protected function processEdit() |
||
208 | |||
209 | /** |
||
210 | * Opens value editing. |
||
211 | * |
||
212 | * @param mixed $value Value. |
||
213 | * |
||
214 | * @return mixed |
||
215 | */ |
||
216 | protected function openEditor($value) |
||
223 | |||
224 | /** |
||
225 | * Deletes setting value. |
||
226 | * |
||
227 | * @return boolean |
||
228 | */ |
||
229 | protected function processDelete() |
||
243 | |||
244 | /** |
||
245 | * Lists values for every stored setting. |
||
246 | * |
||
247 | * @param string $setting_name Setting name. |
||
248 | * |
||
249 | * @return void |
||
250 | */ |
||
251 | protected function listSettings($setting_name = null) |
||
290 | |||
291 | /** |
||
292 | * Returns config settings filtered by scope. |
||
293 | * |
||
294 | * @param integer $scope_filter Scope filter. |
||
295 | * |
||
296 | * @return AbstractConfigSetting[] |
||
297 | */ |
||
298 | protected function getConfigSettingsByScope($scope_filter) |
||
310 | |||
311 | /** |
||
312 | * Validates setting name. |
||
313 | * |
||
314 | * @param string $name Setting name. |
||
315 | * |
||
316 | * @return AbstractConfigSetting |
||
317 | * @throws \InvalidArgumentException When non-existing/outside of scope setting given. |
||
318 | */ |
||
319 | protected function getConfigSetting($name) |
||
333 | |||
334 | /** |
||
335 | * Returns scope filter for viewing config settings. |
||
336 | * |
||
337 | * @return integer |
||
338 | */ |
||
339 | protected function getScopeFilter() |
||
343 | |||
344 | /** |
||
345 | * Returns value filter for editing config settings. |
||
346 | * |
||
347 | * @return integer |
||
348 | */ |
||
349 | protected function getValueFilter() |
||
353 | |||
354 | /** |
||
355 | * Returns possible settings with their defaults. |
||
356 | * |
||
357 | * @return AbstractConfigSetting[] |
||
358 | */ |
||
359 | protected function getConfigSettings() |
||
382 | |||
383 | /** |
||
384 | * Determines if global only config settings should be used. |
||
385 | * |
||
386 | * @return boolean |
||
387 | */ |
||
388 | protected function isGlobal() |
||
397 | |||
398 | } |
||
399 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..