| Conditions | 11 |
| Paths | 32 |
| Total Lines | 70 |
| Code Lines | 45 |
| Lines | 26 |
| Ratio | 37.14 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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 |
||
| 125 | private function askForArguments($input, $output) |
||
| 126 | { |
||
| 127 | $helper = $this->getHelper('question'); |
||
| 128 | $_argument = array(); |
||
| 129 | |||
| 130 | // Store ID |
||
| 131 | if(is_null($input->getArgument('store-id'))) { |
||
| 132 | $store_id = Mage::getModel('core/store')->getCollection() |
||
| 133 | ->addFieldToSelect('*') |
||
| 134 | ->addFieldToFilter('store_id', array('gt' => 0)) |
||
| 135 | ->setOrder('store_id', 'ASC'); |
||
| 136 | $_store_ids = array(); |
||
| 137 | |||
| 138 | foreach($store_id as $item) { |
||
| 139 | $_store_ids[$item['store_id']] = $item['store_id']."|".$item['code']; |
||
| 140 | } |
||
| 141 | |||
| 142 | $question = new ChoiceQuestion('Please select Store ID (default: 1)', $_store_ids, self::DEFAULT_STORE_ID); |
||
| 143 | $question->setErrorMessage('Store ID "%s" is invalid.'); |
||
| 144 | $response = explode("|", $helper->ask($input, $output, $question)); |
||
| 145 | $input->setArgument('store-id', $response[0]); |
||
| 146 | } |
||
| 147 | $output->writeln('<info>Store ID selected: '.$input->getArgument('store-id')."</info>"); |
||
| 148 | $_argument['store-id'] = $input->getArgument('store-id'); |
||
| 149 | |||
| 150 | // Number of Categories |
||
| 151 | View Code Duplication | if(is_null($input->getArgument('category-number'))) { |
|
| 152 | $question = new Question("Please enter the number of categories to create (default 1): ", 1); |
||
| 153 | $question->setValidator(function($answer) { |
||
| 154 | $answer = (int)($answer); |
||
| 155 | if(!is_int($answer) || $answer <= 0) { |
||
| 156 | throw new \RuntimeException('Please enter an integer value or > 0'); |
||
| 157 | } |
||
| 158 | |||
| 159 | return $answer; |
||
| 160 | }); |
||
| 161 | $input->setArgument('category-number', $helper->ask($input, $output, $question)); |
||
| 162 | } |
||
| 163 | $output->writeln('<info>Number of categories to create: '.$input->getArgument('category-number')."</info>"); |
||
| 164 | $_argument['category-number'] = $input->getArgument('category-number'); |
||
| 165 | |||
| 166 | // Number of children categories |
||
| 167 | View Code Duplication | if(is_null($input->getArgument('children-categories-number'))) { |
|
| 168 | $question = new Question("Number of children for each category created (default: 0 - use '-1' for random from 0 to 5): ", 0); |
||
| 169 | $question->setValidator(function($answer) { |
||
| 170 | $answer = (int)($answer); |
||
| 171 | if(!is_int($answer) || $answer < -1) { |
||
| 172 | throw new \RuntimeException("Please enter an integer value or >= -1"); |
||
| 173 | } |
||
| 174 | |||
| 175 | return $answer; |
||
| 176 | }); |
||
| 177 | $input->setArgument('children-categories-number', $helper->ask($input, $output, $question)); |
||
| 178 | } |
||
| 179 | if($input->getArgument('children-categories-number') == -1) |
||
| 180 | $input->setArgument('children-categories-number', rand(0, 5)); |
||
| 181 | |||
| 182 | $output->writeln('<info>Number of categories children to create: '.$input->getArgument('children-categories-number')."</info>"); |
||
| 183 | $_argument['children-categories-number'] = $input->getArgument('children-categories-number'); |
||
| 184 | |||
| 185 | // Category name prefix |
||
| 186 | if(is_null($input->getArgument('category-name-prefix'))) { |
||
| 187 | $question = new Question("Please enter the category name prefix (default '".self::DEFAULT_CATEGORY_NAME."'): ", self::DEFAULT_CATEGORY_NAME); |
||
| 188 | $input->setArgument('category-name-prefix', $helper->ask($input, $output, $question)); |
||
| 189 | } |
||
| 190 | $output->writeln('<info>CATEGORY NAME PREFIX: '.$input->getArgument('category-name-prefix')."</info>"); |
||
| 191 | $_argument['category-name-prefix'] = $input->getArgument('category-name-prefix'); |
||
| 192 | |||
| 193 | return $_argument; |
||
| 194 | } |
||
| 195 | } |
||
| 196 |
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.