| Conditions | 10 |
| Paths | 120 |
| Total Lines | 56 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 34 | protected function doExecute(InputInterface $input, OutputInterface $output): int |
||
| 35 | { |
||
| 36 | OutputHelper::renderHeader($output); |
||
| 37 | |||
| 38 | $minScore = $input->getOption('score'); |
||
| 39 | |||
| 40 | $this->enrichRepositories(); |
||
| 41 | |||
| 42 | $pattern = $input->getArgument('pattern'); |
||
| 43 | |||
| 44 | if (count($pattern) == 1 && str_contains($pattern[0], ' ')) { |
||
| 45 | $pattern = explode(' ', $pattern[0]); |
||
| 46 | } |
||
| 47 | |||
| 48 | $this->renderInfoBox('This is a list of commands that match the given pattern. Sorted by relevance.'); |
||
| 49 | |||
| 50 | $commands = $this->getRepositoryCollection()->searchByPattern($pattern); |
||
| 51 | |||
| 52 | $filteredCommands = []; |
||
| 53 | $perfectCommands = []; |
||
| 54 | |||
| 55 | foreach ($commands as $key => $command) { |
||
| 56 | |||
| 57 | // var_dump($command->getName() . ' - ' . $command->getScore()); |
||
| 58 | |||
| 59 | if ($command->getScore() > $minScore) { |
||
| 60 | $filteredCommands[$key] = $command; |
||
| 61 | } |
||
| 62 | |||
| 63 | if ($command->getScore() > self::PERFECT_SCORE) { |
||
| 64 | $perfectCommands[$key] = $command; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | if (count($filteredCommands) == 0) { |
||
| 69 | $filteredCommands = $commands; |
||
| 70 | } |
||
| 71 | |||
| 72 | if (count($perfectCommands) > 0) { |
||
| 73 | $filteredCommands = $perfectCommands; |
||
| 74 | } |
||
| 75 | |||
| 76 | if (empty($filteredCommands)) { |
||
| 77 | $this->renderErrorBox('No commands found that match the given pattern.'); |
||
| 78 | return Command::FAILURE; |
||
| 79 | } |
||
| 80 | |||
| 81 | $result = $this->runFromCommands($filteredCommands, [], true); |
||
| 82 | |||
| 83 | if ($result !== true) { |
||
| 84 | return $result; |
||
| 85 | } |
||
| 86 | |||
| 87 | $this->renderInfoBox('We are asking the Forrest AI...'); |
||
| 88 | |||
| 89 | return $this->runAiAskCommand($pattern); |
||
| 90 | } |
||
| 110 |