| Conditions | 10 |
| Paths | 50 |
| Total Lines | 52 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 31 | protected function doExecute(InputInterface $input, OutputInterface $output): int |
||
| 32 | { |
||
| 33 | $this->enrichRepositories(); |
||
| 34 | |||
| 35 | $silent = $input->getOption('silent'); |
||
| 36 | |||
| 37 | if (!$silent) { |
||
| 38 | \Startwind\Forrest\Output\OutputHelper::renderHeader($output); |
||
| 39 | } |
||
| 40 | |||
| 41 | $aiQuestion = trim(implode(' ', $input->getArgument('question'))); |
||
| 42 | |||
| 43 | if ($aiQuestion == 'how') { |
||
| 44 | OutputHelper::writeErrorBox($output, ["Please provide a question."]); |
||
| 45 | return SymfonyCommand::FAILURE; |
||
| 46 | } |
||
| 47 | |||
| 48 | if ($aiQuestion && !str_ends_with($aiQuestion, '?')) { |
||
| 49 | $aiQuestion = $aiQuestion . '?'; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** @var \Symfony\Component\Console\Helper\QuestionHelper $questionHelper */ |
||
| 53 | $questionHelper = $this->getHelper('question'); |
||
| 54 | |||
| 55 | if (!$aiQuestion) { |
||
| 56 | OutputHelper::writeInfoBox($output, ["Hi, I am Forrest, your AI command line helper. How can I help you?"]); |
||
| 57 | $output->writeln(''); |
||
| 58 | $aiQuestion = $questionHelper->ask($input, $output, new Question(' Your question: ')); |
||
| 59 | $output->writeln(['', '']); |
||
| 60 | } else { |
||
| 61 | if (!$silent) { |
||
| 62 | OutputHelper::writeInfoBox($output, [ |
||
| 63 | "Question: " . ucfirst($aiQuestion) |
||
| 64 | ]); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | $answers = $this->getRepositoryCollection()->ask($aiQuestion); |
||
| 69 | |||
| 70 | foreach ($answers as $repoAnswers) { |
||
| 71 | foreach ($repoAnswers as $answer) { |
||
| 72 | /** @var Answer $answer */ |
||
| 73 | $output->writeln(OutputHelper::indentText($this->formatCliText($answer->getAnswer()))); |
||
| 74 | $command = $answer->getCommand(); |
||
| 75 | |||
| 76 | if ($command->getPrompt()) { |
||
| 77 | return $this->runCommand($answer->getCommand(), []); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | return SymfonyCommand::SUCCESS; |
||
| 83 | } |
||
| 108 |