Conditions | 11 |
Paths | 32 |
Total Lines | 80 |
Code Lines | 50 |
Lines | 26 |
Ratio | 32.5 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
123 | protected function manageArguments($input, $output) |
||
124 | { |
||
125 | /** |
||
126 | * ARGUMENTS |
||
127 | */ |
||
128 | $helper = $this->getHelper('question'); |
||
129 | $_argument = array(); |
||
130 | |||
131 | // STORE ID |
||
132 | if(is_null($input->getArgument('store-id'))) { |
||
133 | $store_id = \Mage::getModel('core/store')->getCollection() |
||
134 | ->addFieldToSelect('*') |
||
135 | ->addFieldToFilter('store_id', array('gt' => 0)) |
||
136 | ->setOrder('store_id', 'ASC');; |
||
137 | $_store_ids = array(); |
||
138 | |||
139 | foreach ($store_id as $item) { |
||
140 | $_store_ids[$item['store_id']] = $item['store_id'] . "|" . $item['code']; |
||
141 | } |
||
142 | |||
143 | $question = new ChoiceQuestion( |
||
144 | 'Please select Store ID (default: 1)', |
||
145 | $_store_ids, |
||
146 | self::DEFAULT_STORE_ID |
||
147 | ); |
||
148 | $question->setErrorMessage('Store ID "%s" is invalid.'); |
||
149 | $response = explode("|", $helper->ask($input, $output, $question)); |
||
150 | $input->setArgument('store-id', $response[0]); |
||
151 | } |
||
152 | $output->writeln('<info>Store ID selected: ' . $input->getArgument('store-id') . "</info>\r\n"); |
||
153 | $_argument['store-id'] = $input->getArgument('store-id'); |
||
154 | |||
155 | // NUMBER OF CATEGORIES |
||
156 | View Code Duplication | if(is_null($input->getArgument('category-number'))) { |
|
157 | $question = new Question("Please enter the number of categories to create (default 1): ", 1); |
||
158 | $question->setValidator(function ($answer) { |
||
159 | $answer = (int)($answer); |
||
160 | if(!is_int($answer) || $answer <= 0) { |
||
161 | throw new \RuntimeException( |
||
162 | 'Please enter an integer value or > 0' |
||
163 | ); |
||
164 | } |
||
165 | return $answer; |
||
166 | }); |
||
167 | $input->setArgument('category-number', $helper->ask($input, $output, $question)); |
||
168 | } |
||
169 | $output->writeln('<info>Number of categories to create: ' . $input->getArgument('category-number') . "</info>\r\n"); |
||
170 | $_argument['category-number'] = $input->getArgument('category-number'); |
||
171 | |||
172 | // NUMBER OF CHILDREN CATEGORIES |
||
173 | View Code Duplication | if(is_null($input->getArgument('children-categories-number'))) { |
|
174 | $question = new Question("Number of children for each category created (default: 0 - use '-1' for random from 0 to 5): ", 0); |
||
175 | $question->setValidator(function ($answer) { |
||
176 | $answer = (int)($answer); |
||
177 | if(!is_int($answer) || $answer < -1) { |
||
178 | throw new \RuntimeException( |
||
179 | "Please enter an integer value or >= -1" |
||
180 | ); |
||
181 | } |
||
182 | return $answer; |
||
183 | }); |
||
184 | $input->setArgument('children-categories-number', $helper->ask($input, $output, $question)); |
||
185 | } |
||
186 | if($input->getArgument('children-categories-number') == -1) { |
||
187 | $input->setArgument('children-categories-number', rand(0, 5)); |
||
188 | } |
||
189 | |||
190 | $output->writeln('<info>Number of categories children to create: ' . $input->getArgument('children-categories-number') . "</info>\r\n"); |
||
191 | $_argument['children-categories-number'] = $input->getArgument('children-categories-number'); |
||
192 | |||
193 | // CATEGORY NAME PREFIX |
||
194 | if(is_null($input->getArgument('category-name-prefix'))) { |
||
195 | $question = new Question("Please enter the category name prefix (default '" . self::DEFAULT_CATEGORY_NAME . "'): ", self::DEFAULT_CATEGORY_NAME); |
||
196 | $input->setArgument('category-name-prefix', $helper->ask($input, $output, $question)); |
||
197 | } |
||
198 | $output->writeln('<info>CATEGORY NAME PREFIX: ' . $input->getArgument('category-name-prefix') . "</info>\r\n"); |
||
199 | $_argument['category-name-prefix'] = $input->getArgument('category-name-prefix'); |
||
200 | |||
201 | return $_argument; |
||
202 | } |
||
203 | } |
||
204 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.