Conditions | 7 |
Paths | 8 |
Total Lines | 53 |
Code Lines | 35 |
Lines | 13 |
Ratio | 24.53 % |
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 |
||
83 | private function askForArguments(InputInterface $input, OutputInterface $output) |
||
84 | { |
||
85 | $helper = $this->getHelper('question'); |
||
86 | $argument = array(); |
||
87 | |||
88 | // Attribute ID |
||
89 | if (is_null($input->getArgument('attribute-id'))) { |
||
90 | $attribute_code = Mage::getModel('eav/entity_attribute')->getCollection()->addFieldToSelect('*') |
||
91 | ->addFieldToFilter('entity_type_id', array('eq' => 4)) |
||
92 | ->addFieldToFilter('backend_type', array('in' => array('int'))) |
||
93 | ->setOrder('attribute_id', 'ASC'); |
||
94 | $attribute_codes = array(); |
||
95 | |||
96 | foreach ($attribute_code as $item) { |
||
97 | $attribute_codes[$item['attribute_id']] = $item['attribute_id'] . "|" . $item['attribute_code']; |
||
98 | } |
||
99 | |||
100 | $question = new ChoiceQuestion('Please select Attribute ID', $attribute_codes); |
||
101 | $question->setErrorMessage('Attribute ID "%s" is invalid.'); |
||
102 | $response = explode("|", $helper->ask($input, $output, $question)); |
||
103 | $input->setArgument('attribute-id', $response[0]); |
||
104 | } |
||
105 | $output->writeln('<info>Attribute code selected: ' . $input->getArgument('attribute-id') . "</info>"); |
||
106 | $argument['attribute-id'] = (int) $input->getArgument('attribute-id'); |
||
107 | |||
108 | // Type of Values |
||
109 | if (is_null($input->getArgument('values-type'))) { |
||
110 | $valueTypes = DummyValues::getValueTypeList(); |
||
111 | $question = new ChoiceQuestion('Please select Attribute Value Type', $valueTypes, 'int'); |
||
112 | $question->setErrorMessage('Attribute Value Type "%s" is invalid.'); |
||
113 | $input->setArgument('values-type', $helper->ask($input, $output, $question)); |
||
114 | } |
||
115 | $output->writeln('<info>Attribute Value Type selected: ' . $input->getArgument('values-type') . "</info>"); |
||
116 | $argument['values-type'] = $input->getArgument('values-type'); |
||
117 | |||
118 | // Number of Values |
||
119 | View Code Duplication | if (is_null($input->getArgument('values-number'))) { |
|
120 | $question = new Question("Please enter the number of values to create (default 1): ", 1); |
||
121 | $question->setValidator(function ($answer) { |
||
122 | $answer = (int) ($answer); |
||
123 | if (!is_int($answer) || $answer <= 0) { |
||
124 | throw new \RuntimeException('Please enter an integer value or > 0'); |
||
125 | } |
||
126 | |||
127 | return $answer; |
||
128 | }); |
||
129 | $input->setArgument('values-number', $helper->ask($input, $output, $question)); |
||
130 | } |
||
131 | $output->writeln('<info>Number of values to create: ' . $input->getArgument('values-number') . "</info>"); |
||
132 | $argument['values-number'] = $input->getArgument('values-number'); |
||
133 | |||
134 | return $argument; |
||
135 | } |
||
136 | |||
160 |
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.