| Conditions | 10 |
| Paths | 70 |
| Total Lines | 66 |
| Code Lines | 39 |
| 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 |
||
| 14 | protected function renderListCommand(string $repository = ''): void |
||
| 15 | { |
||
| 16 | $output = $this->getOutput(); |
||
| 17 | |||
| 18 | OutputHelper::renderHeader($output); |
||
| 19 | |||
| 20 | $this->enrichRepositories(); |
||
| 21 | |||
| 22 | $maxLength = 0; |
||
| 23 | |||
| 24 | if ($repository) { |
||
| 25 | $repositories = [$repository => $this->getRepositoryCollection()->getRepository($repository)]; |
||
| 26 | } else { |
||
| 27 | $repositories = $this->getRepositoryCollection()->getRepositories(); |
||
| 28 | } |
||
| 29 | |||
| 30 | foreach ($repositories as $repoIdentifier => $repository) { |
||
| 31 | if ($repository instanceof ListAware) { |
||
| 32 | try { |
||
| 33 | foreach ($repository->getCommands(false) as $command) { |
||
| 34 | $maxLength = max($maxLength, strlen(RepositoryCollection::createUniqueCommandName($repoIdentifier, $command))); |
||
| 35 | } |
||
| 36 | } catch (\Exception $exception) { |
||
| 37 | unset($repositories[$repoIdentifier]); |
||
| 38 | $this->renderErrorBox([ |
||
| 39 | 'Unable to fetch commands from ' . $repoIdentifier . '. ' . $exception->getMessage(), |
||
| 40 | ]); |
||
| 41 | $output->writeln(''); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | $output->writeln([ |
||
| 47 | '<fg=yellow>Usage:</>', |
||
| 48 | '', |
||
| 49 | ' forrest run [command]', |
||
| 50 | '', |
||
| 51 | ]); |
||
| 52 | |||
| 53 | foreach ($repositories as $repoIdentifier => $repository) { |
||
| 54 | if (!$repository instanceof ListAware) { |
||
| 55 | continue; |
||
| 56 | } |
||
| 57 | |||
| 58 | if (!$repository->hasCommands()) { |
||
| 59 | continue; |
||
| 60 | } |
||
| 61 | |||
| 62 | if ($repository->isSpecial()) { |
||
| 63 | $this->renderWarningBox($repository->getName() . ' (' . $repoIdentifier . ')'); |
||
| 64 | $output->writeln([' ' . $repository->getDescription(), '']); |
||
| 65 | } else { |
||
| 66 | $output->writeln([ |
||
| 67 | '', |
||
| 68 | '<fg=yellow>' . $repository->getName() . '</> (' . $repoIdentifier . ')', |
||
| 69 | '', |
||
| 70 | ]); |
||
| 71 | } |
||
| 72 | |||
| 73 | /** @var \Symfony\Component\Console\Helper\QuestionHelper $questionHelper */ |
||
| 74 | $questionHelper = $this->getHelper('question'); |
||
| 75 | |||
| 76 | OutputHelper::renderCommands($output, $this->getInput(), $questionHelper, $repository->getCommands(false), $repoIdentifier, $maxLength); |
||
| 77 | } |
||
| 78 | |||
| 79 | $output->writeln(''); |
||
| 80 | } |
||
| 82 |