| Conditions | 20 |
| Paths | 1394 |
| Total Lines | 98 |
| Code Lines | 58 |
| 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 |
||
| 27 | protected function doExecute(InputInterface $input, OutputInterface $output): int |
||
| 28 | { |
||
| 29 | $this->initRepositoryLoader(); |
||
| 30 | $activeRepositories = $this->getRepositoryLoader()->getIdentifiers(); |
||
| 31 | |||
| 32 | try { |
||
| 33 | $directories = $this->getDirectories(); |
||
| 34 | } catch (DirectoriesLoadException $exception) { |
||
| 35 | $directories = $exception->getDirectories(); |
||
| 36 | $messages = []; |
||
| 37 | foreach ($exception->getExceptions() as $exception) { |
||
| 38 | $messages[] = $exception->getMessage(); |
||
| 39 | } |
||
| 40 | OutputHelper::writeErrorBox($output, $messages); |
||
| 41 | } |
||
| 42 | |||
| 43 | $repositories = []; |
||
| 44 | |||
| 45 | foreach ($directories as $identifier => $directory) { |
||
| 46 | if (!array_key_exists('repositories', $directory)) { |
||
| 47 | throw new \RuntimeException('No repositories found in the given directory (' . $identifier . ').'); |
||
| 48 | } |
||
| 49 | |||
| 50 | foreach ($directory['repositories'] as $repoIdentifier => $repository) { |
||
| 51 | $repositories[$identifier][$repoIdentifier] = $repository; |
||
| 52 | } |
||
| 53 | |||
| 54 | ksort($repositories[$identifier]); |
||
| 55 | } |
||
| 56 | |||
| 57 | ksort($repositories); |
||
| 58 | |||
| 59 | $rows = []; |
||
| 60 | |||
| 61 | $all = $input->getOption('all') !== false; |
||
| 62 | |||
| 63 | $unofficialCount = 0; |
||
| 64 | |||
| 65 | $dirCount = 0; |
||
| 66 | foreach ($repositories as $directoryIdentifier => $directoryRepositories) { |
||
| 67 | foreach ($directoryRepositories as $identifier => $repository) { |
||
| 68 | if ($all || (array_key_exists('official', $repository) && $repository['official'] === true)) { |
||
| 69 | $row = [ |
||
| 70 | $identifier, |
||
| 71 | $repository['name'], |
||
| 72 | wordwrap($repository['description'], 55), |
||
| 73 | ]; |
||
| 74 | |||
| 75 | if (count($directories) > 1) { |
||
| 76 | array_unshift($row, $directoryIdentifier); |
||
| 77 | } |
||
| 78 | |||
| 79 | if (in_array($identifier, $activeRepositories)) { |
||
| 80 | $row[] = 'x'; |
||
| 81 | } else { |
||
| 82 | $row[] = ''; |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($all) { |
||
| 86 | if (array_key_exists('official', $repository) && $repository['official'] === true) { |
||
| 87 | $row[] = 'x'; |
||
| 88 | } else { |
||
| 89 | $row[] = ''; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | $rows [] = $row; |
||
| 94 | } else { |
||
| 95 | $unofficialCount++; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | if ($dirCount != count($directories) - 1) { |
||
| 99 | $rows[] = new TableSeparator(); |
||
| 100 | } |
||
| 101 | $dirCount++; |
||
| 102 | } |
||
| 103 | |||
| 104 | $headers = ['Identifier', 'Name', 'Description', 'Installed']; |
||
| 105 | |||
| 106 | if (count($directories) > 1) { |
||
| 107 | array_unshift($headers, 'Directory'); |
||
| 108 | } |
||
| 109 | |||
| 110 | if ($all) { |
||
| 111 | $headers[] = 'Official'; |
||
| 112 | } |
||
| 113 | |||
| 114 | TableOutputHelper::renderTable($output, $headers, $rows); |
||
| 115 | |||
| 116 | if ($unofficialCount > 0) { |
||
| 117 | $output->writeln([ |
||
| 118 | '', |
||
| 119 | 'This list only contains official repositories. If you also want to see', |
||
| 120 | 'the other ' . $unofficialCount . ' unofficial repositories please use the --all option.' |
||
| 121 | ]); |
||
| 122 | } |
||
| 123 | |||
| 124 | return SymfonyCommand::SUCCESS; |
||
| 125 | } |
||
| 127 |