| Conditions | 11 |
| Paths | 170 |
| Total Lines | 58 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 1 | 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 |
||
| 37 | public static function renderCommands(OutputInterface $output, InputInterface $input, QuestionHelper $questionHelper, array $commands, ?string $repoIdentifier = null, int $maxLength = -1, $askForCommand = false): bool|Command |
||
| 38 | { |
||
| 39 | $identifierMaxLength = $maxLength; |
||
| 40 | |||
| 41 | foreach ($commands as $commandId => $command) { |
||
| 42 | if ($repoIdentifier) { |
||
| 43 | $commandIdentifier = RepositoryCollection::createUniqueCommandName($repoIdentifier, $command); |
||
| 44 | } else { |
||
| 45 | $commandIdentifier = $commandId; |
||
| 46 | } |
||
| 47 | $command->setFullyQualifiedIdentifier($commandIdentifier); |
||
| 48 | if ($maxLength == -1) { |
||
| 49 | $identifierMaxLength = max($identifierMaxLength, strlen($commandIdentifier)); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | uasort($commands, function (Command $a, Command $b) { |
||
| 54 | if($a->getScore() > -1) { |
||
| 55 | return$b->getScore() <=> $a->getScore() ; |
||
| 56 | } |
||
| 57 | return $a->getFullyQualifiedIdentifier() <=> $b->getFullyQualifiedIdentifier(); |
||
| 58 | }); |
||
| 59 | |||
| 60 | $number = 1; |
||
| 61 | $numberPrefix = ''; |
||
| 62 | |||
| 63 | foreach ($commands as $commandId => $command) { |
||
| 64 | if ($repoIdentifier) { |
||
| 65 | $commandIdentifier = RepositoryCollection::createUniqueCommandName($repoIdentifier, $command); |
||
| 66 | } else { |
||
| 67 | $commandIdentifier = $commandId; |
||
| 68 | } |
||
| 69 | |||
| 70 | $spaces = str_repeat(' ', $identifierMaxLength - strlen($commandIdentifier) + 2); |
||
| 71 | |||
| 72 | if ($askForCommand) { |
||
| 73 | $numberPrefix = ' ' . $number; |
||
| 74 | $number++; |
||
| 75 | } |
||
| 76 | |||
| 77 | $placeholder = ''; |
||
| 78 | |||
| 79 | if ($number < 100) { |
||
| 80 | $placeholder = ' '; |
||
| 81 | } |
||
| 82 | |||
| 83 | if ($number < 11) { |
||
| 84 | $placeholder = ' '; |
||
| 85 | } |
||
| 86 | |||
| 87 | $output->writeln($numberPrefix . ' <fg=green>' . $commandIdentifier . '</>' . $placeholder . $spaces . $command->getDescription()); |
||
| 88 | } |
||
| 89 | |||
| 90 | if ($askForCommand) { |
||
| 91 | return self::askForCommand($output, $input, $questionHelper, $commands); |
||
| 92 | } |
||
| 93 | |||
| 94 | return false; |
||
| 95 | } |
||
| 126 |