Complex classes like AbstractMagentoCommand 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 AbstractMagentoCommand, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
24 | abstract class AbstractMagentoCommand extends Command |
||
25 | { |
||
26 | /** |
||
27 | * @var int |
||
28 | */ |
||
29 | const MAGENTO_MAJOR_VERSION_2 = 2; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $_magentoRootFolder = null; |
||
35 | |||
36 | /** |
||
37 | * @var int |
||
38 | */ |
||
39 | protected $_magentoMajorVersion = self::MAGENTO_MAJOR_VERSION_2; |
||
40 | |||
41 | /** |
||
42 | * @var bool |
||
43 | */ |
||
44 | protected $_magentoEnterprise = false; |
||
45 | |||
46 | /** |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $_deprecatedAlias = array(); |
||
50 | |||
51 | /** |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $_websiteCodeMap = array(); |
||
55 | |||
56 | /** |
||
57 | * @var ObjectManager |
||
58 | */ |
||
59 | protected $_objectManager = null; |
||
60 | |||
61 | /** |
||
62 | * Initializes the command just after the input has been validated. |
||
63 | * |
||
64 | * This is mainly useful when a lot of commands extends one main command |
||
65 | * where some things need to be initialized based on the input arguments and options. |
||
66 | * |
||
67 | * @param InputInterface $input An InputInterface instance |
||
68 | * @param OutputInterface $output An OutputInterface instance |
||
69 | */ |
||
70 | protected function initialize(InputInterface $input, OutputInterface $output) |
||
74 | |||
75 | /** |
||
76 | * @return ObjectManager |
||
77 | */ |
||
78 | protected function getObjectManager() |
||
82 | |||
83 | /** |
||
84 | * @param array $codeArgument |
||
85 | * @param bool $status |
||
86 | * @return bool |
||
|
|||
87 | */ |
||
88 | protected function saveCacheStatus($codeArgument, $status) |
||
100 | |||
101 | private function _initWebsites() |
||
110 | |||
111 | /** |
||
112 | * @param int $websiteId |
||
113 | * @return string |
||
114 | */ |
||
115 | protected function _getWebsiteCodeById($websiteId) |
||
127 | |||
128 | /** |
||
129 | * @param string $websiteCode |
||
130 | * @return int |
||
131 | */ |
||
132 | protected function _getWebsiteIdByCode($websiteCode) |
||
141 | |||
142 | /** |
||
143 | * @param string|null $commandClass |
||
144 | * @return array |
||
145 | */ |
||
146 | protected function getCommandConfig($commandClass = null) |
||
158 | |||
159 | /** |
||
160 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
161 | * @param string $text |
||
162 | * @param string $style |
||
163 | */ |
||
164 | protected function writeSection(OutputInterface $output, $text, $style = 'bg=blue;fg=white') |
||
172 | |||
173 | /** |
||
174 | * Bootstrap magento shop |
||
175 | * |
||
176 | * @return bool |
||
177 | */ |
||
178 | protected function initMagento() |
||
187 | |||
188 | /** |
||
189 | * Search for magento root folder |
||
190 | * |
||
191 | * @param OutputInterface $output |
||
192 | * @param bool $silent print debug messages |
||
193 | * @throws \RuntimeException |
||
194 | */ |
||
195 | public function detectMagento(OutputInterface $output, $silent = true) |
||
216 | |||
217 | /** |
||
218 | * Die if not Enterprise |
||
219 | */ |
||
220 | protected function requireEnterprise(OutputInterface $output) |
||
227 | |||
228 | /** |
||
229 | * @return \Mage_Core_Helper_Data |
||
230 | */ |
||
231 | protected function getCoreHelper() |
||
238 | |||
239 | /** |
||
240 | * @param InputInterface $input |
||
241 | * @param OutputInterface $output |
||
242 | * @return \Composer\Downloader\DownloadManager |
||
243 | */ |
||
244 | public function getComposerDownloadManager($input, $output) |
||
248 | |||
249 | /** |
||
250 | * @param array|PackageInterface $config |
||
251 | * @return \Composer\Package\CompletePackage |
||
252 | */ |
||
253 | public function createComposerPackageByConfig($config) |
||
258 | |||
259 | /** |
||
260 | * @param InputInterface $input |
||
261 | * @param OutputInterface $output |
||
262 | * @param array|PackageInterface $config |
||
263 | * @param string $targetFolder |
||
264 | * @param bool $preferSource |
||
265 | * @return \Composer\Package\CompletePackage |
||
266 | */ |
||
267 | public function downloadByComposerConfig( |
||
293 | |||
294 | /** |
||
295 | * brings locally cached repository up to date if it is missing the requested tag |
||
296 | * |
||
297 | * @param $package |
||
298 | * @param $targetFolder |
||
299 | */ |
||
300 | protected function checkRepository($package, $targetFolder) |
||
326 | |||
327 | /** |
||
328 | * @param string $type |
||
329 | * |
||
330 | * @return bool |
||
331 | */ |
||
332 | public function isSourceTypeRepository($type) |
||
336 | |||
337 | /** |
||
338 | * obtain composer |
||
339 | * |
||
340 | * @param InputInterface $input |
||
341 | * @param OutputInterface $output |
||
342 | * |
||
343 | * @return \Composer\Composer |
||
344 | */ |
||
345 | public function getComposer(InputInterface $input, OutputInterface $output) |
||
356 | |||
357 | /** |
||
358 | * @param string $alias |
||
359 | * @param string $message |
||
360 | * @return AbstractMagentoCommand |
||
361 | */ |
||
362 | protected function addDeprecatedAlias($alias, $message) |
||
368 | |||
369 | /** |
||
370 | * @param InputInterface $input |
||
371 | * @param OutputInterface $output |
||
372 | */ |
||
373 | protected function checkDeprecatedAliases(InputInterface $input, OutputInterface $output) |
||
382 | |||
383 | /** |
||
384 | * @param string $value |
||
385 | * @return bool |
||
386 | */ |
||
387 | protected function _parseBoolOption($value) |
||
391 | |||
392 | /** |
||
393 | * @param string $value |
||
394 | * @return bool |
||
395 | */ |
||
396 | public function parseBoolOption($value) |
||
400 | |||
401 | /** |
||
402 | * @param string $value |
||
403 | * @return string |
||
404 | */ |
||
405 | public function formatActive($value) |
||
413 | |||
414 | /** |
||
415 | * @param InputInterface $input |
||
416 | * @param OutputInterface $output |
||
417 | * |
||
418 | * @return int |
||
419 | */ |
||
420 | public function run(InputInterface $input, OutputInterface $output) |
||
428 | |||
429 | /** |
||
430 | * @param OutputInterface $output |
||
431 | */ |
||
432 | public function injectObjects(OutputInterface $output) |
||
446 | |||
447 | /** |
||
448 | * @param InputInterface $input |
||
449 | * @param OutputInterface $output |
||
450 | * @param string $baseNamespace If this is set we can use relative class names. |
||
451 | * |
||
452 | * @return SubCommandFactory |
||
453 | */ |
||
454 | protected function createSubCommandFactory( |
||
475 | } |
||
476 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.