Complex classes like MetaCommand 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 MetaCommand, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | class MetaCommand extends AbstractMagentoCommand |
||
16 | { |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $groups = array( |
||
21 | 'blocks', |
||
22 | 'helpers', |
||
23 | 'models', |
||
24 | 'resource models', |
||
25 | 'resource helpers', |
||
26 | ); |
||
27 | |||
28 | /** |
||
29 | * List of supported static factory methods |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $groupFactories = array( |
||
34 | 'blocks' => array( |
||
35 | '\Mage::getBlockSingleton', |
||
36 | ), |
||
37 | 'helpers' => array( |
||
38 | '\Mage::helper', |
||
39 | ), |
||
40 | 'models' => array( |
||
41 | '\Mage::getModel', |
||
42 | '\Mage::getSingleton', |
||
43 | ), |
||
44 | 'resource helpers' => array( |
||
45 | '\Mage::getResourceHelper', |
||
46 | ), |
||
47 | 'resource models' => array( |
||
48 | '\Mage::getResourceModel', |
||
49 | '\Mage::getResourceSingleton', |
||
50 | ), |
||
51 | ); |
||
52 | |||
53 | /** |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $missingHelperDefinitionModules = array( |
||
57 | 'Backup', |
||
58 | 'Bundle', |
||
59 | 'Captcha', |
||
60 | 'Catalog', |
||
61 | 'Centinel', |
||
62 | 'Checkout', |
||
63 | 'Cms', |
||
64 | 'Core', |
||
65 | 'Customer', |
||
66 | 'Dataflow', |
||
67 | 'Directory', |
||
68 | 'Downloadable', |
||
69 | 'Eav', |
||
70 | 'Index', |
||
71 | 'Install', |
||
72 | 'Log', |
||
73 | 'Media', |
||
74 | 'Newsletter', |
||
75 | 'Page', |
||
76 | 'Payment', |
||
77 | 'Paypal', |
||
78 | 'Persistent', |
||
79 | 'Poll', |
||
80 | 'Rating', |
||
81 | 'Reports', |
||
82 | 'Review', |
||
83 | 'Rss', |
||
84 | 'Rule', |
||
85 | 'Sales', |
||
86 | 'Shipping', |
||
87 | 'Sitemap', |
||
88 | 'Tag', |
||
89 | 'Tax', |
||
90 | 'Usa', |
||
91 | 'Weee', |
||
92 | 'Widget', |
||
93 | 'Wishlist', |
||
94 | ); |
||
95 | |||
96 | protected function configure() |
||
97 | { |
||
98 | $this |
||
99 | ->setName('dev:ide:phpstorm:meta') |
||
100 | ->addOption('stdout', null, InputOption::VALUE_NONE, 'Print to stdout instead of file .phpstorm.meta.php') |
||
101 | ->setDescription('Generates meta data file for PhpStorm auto completion') |
||
102 | ; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @param InputInterface $input |
||
107 | * @param OutputInterface $output |
||
108 | * |
||
109 | * @internal param string $package |
||
110 | * @return void |
||
111 | */ |
||
112 | protected function execute(InputInterface $input, OutputInterface $output) |
||
137 | |||
138 | /** |
||
139 | * @param SplFileInfo $file |
||
140 | * @param string $classPrefix |
||
141 | * @return string |
||
142 | */ |
||
143 | protected function getRealClassname(SplFileInfo $file, $classPrefix) |
||
156 | |||
157 | /** |
||
158 | * @param SplFileInfo $file |
||
159 | * @param string $classPrefix |
||
160 | * @param string $group |
||
161 | * @return string |
||
162 | */ |
||
163 | protected function getClassIdentifier(SplFileInfo $file, $classPrefix, $group = '') |
||
175 | |||
176 | /** |
||
177 | * Verify whether given class is defined in given file because there is no sense in adding class with incorrect |
||
178 | * file or path. Examples: |
||
179 | * app/code/core/Mage/Core/Model/Mysql4/Design/Theme/Collection.php -> Mage_Core_Model_Mysql4_Design_Theme |
||
180 | * app/code/core/Mage/Payment/Model/Paygate/Request.php -> Mage_Paygate_Model_Authorizenet_Request |
||
181 | * app/code/core/Mage/Dataflow/Model/Convert/Iterator.php -> Mage_Dataflow_Model_Session_Adapter_Iterator |
||
182 | * |
||
183 | * @param SplFileInfo $file |
||
184 | * @param string $className |
||
185 | * @param OutputInterface $output |
||
186 | * @return bool |
||
187 | */ |
||
188 | protected function isClassDefinedInFile(SplFileInfo $file, $className, OutputInterface $output) |
||
197 | |||
198 | /** |
||
199 | * Resource helper is always one per module for each db type and uses model alias |
||
200 | * |
||
201 | * @return array |
||
202 | */ |
||
203 | protected function getResourceHelperMap() |
||
223 | |||
224 | /** |
||
225 | * @param string $group |
||
226 | * @param OutputInterface $output |
||
227 | * |
||
228 | *@return array |
||
229 | */ |
||
230 | protected function getClassMapForGroup($group, OutputInterface $output) |
||
331 | |||
332 | /** |
||
333 | * @param InputInterface $input |
||
334 | * @param OutputInterface $output |
||
335 | * @param $classMaps |
||
336 | */ |
||
337 | protected function writeToOutput(InputInterface $input, OutputInterface $output, $classMaps) |
||
369 | |||
370 | /** |
||
371 | * @param string $group |
||
372 | * @return \Mage_Core_Model_Config_Element |
||
373 | */ |
||
374 | protected function getGroupXmlDefinition($group) |
||
407 | } |
||
408 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: