| Conditions | 24 |
| Paths | 79 |
| Total Lines | 80 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 157 | protected function makeLineRequest($params) |
||
| 158 | { |
||
| 159 | //nesting loop protection |
||
| 160 | if ($this->getNestingLevel() < 0) { |
||
| 161 | rewind($this->output->getStream()); |
||
| 162 | $display = stream_get_contents($this->output->getStream()); |
||
| 163 | throw new \Exception($display); |
||
| 164 | } |
||
| 165 | $this->nestingLevel--; |
||
| 166 | |||
| 167 | $this->output->writeln($params['name']); |
||
| 168 | $Question = new Question('<comment>Input' . self::INPUT_OPEN . $params['no'] . self::INPUT_CLOSE . ' : </comment>', ''); |
||
| 169 | $value = $this->dialog->ask($this->input, $this->output, $Question); |
||
| 170 | $value = trim($value); |
||
| 171 | if ($value === self::STOP_PROCESS) { |
||
| 172 | return false; |
||
| 173 | } |
||
| 174 | foreach ($params['validation'] as $key => $row) { |
||
| 175 | |||
| 176 | if ($key == 'isRequired' && $row == true) { |
||
| 177 | if ($value === '' || strlen($value) == 0) { |
||
| 178 | |||
| 179 | $this->output->writeln('[!] Value cannot be empty.'); |
||
| 180 | return $this->makeLineRequest($params); |
||
| 181 | } |
||
| 182 | } elseif ($key == 'patern' && preg_match($row, $value) == false) { |
||
| 183 | $this->output->writeln('<error>[!] Value is not valid.</error>'); |
||
| 184 | return $this->makeLineRequest($params); |
||
| 185 | } elseif ($key == 'inArray' || $key == 'choice') { |
||
| 186 | |||
| 187 | if (is_string($row)) { |
||
| 188 | $row = $this->$row(); |
||
| 189 | } |
||
| 190 | if ($value == '') { |
||
| 191 | return $params['value']; |
||
| 192 | } |
||
| 193 | if (isset($row[$value])) { |
||
| 194 | if (!is_array($params['value'])) { |
||
| 195 | $value = $row[$value]; |
||
| 196 | continue; |
||
| 197 | } |
||
| 198 | $params['value'][$value] = $row[$value]; |
||
| 199 | $this->output->writeln('<info>--- your entry list</info>'); |
||
| 200 | foreach ($params['value'] as $subKey => $node) { |
||
| 201 | $this->output->writeln('<info> - ' . $subKey . '</info>'); |
||
| 202 | } |
||
| 203 | $this->output->writeln(''); |
||
| 204 | $this->output->writeln('--- Press Enter to move to the next step ---'); |
||
| 205 | |||
| 206 | return $this->makeLineRequest($params); |
||
| 207 | } else { |
||
| 208 | $searchList = array(); |
||
| 209 | $max = 16; |
||
| 210 | foreach ($row as $eventKey => $eventConst) { |
||
| 211 | if (strpos($eventKey, $value) !== false || strpos($eventConst, $value) !== false) { |
||
| 212 | if (count($searchList) >= $max) { |
||
| 213 | $searchList['-- there are more then ' . $max . ''] = ''; |
||
| 214 | break; |
||
| 215 | } |
||
| 216 | $searchList[$eventKey] = $eventConst; |
||
| 217 | } |
||
| 218 | } |
||
| 219 | $this->output->writeln('<error>[!] No results have been found</error>'); |
||
| 220 | if (!empty($searchList)) { |
||
| 221 | $this->output->writeln('--- there are more then one search result'); |
||
| 222 | } |
||
| 223 | foreach ($searchList as $subKey => $node) { |
||
| 224 | $this->output->writeln(' - ' . $subKey); |
||
| 225 | } |
||
| 226 | |||
| 227 | if (!empty($searchList)) { |
||
| 228 | $this->output->writeln(''); |
||
| 229 | } |
||
| 230 | return $this->makeLineRequest($params); |
||
| 231 | } |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | return $value; |
||
| 236 | } |
||
| 237 | |||
| 248 |