| Total Complexity | 8 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class Legend implements ApplicationHandlerInterface |
||
| 11 | { |
||
| 12 | public const KEY = '--list'; |
||
| 13 | |||
| 14 | 8 | public function __construct(private readonly Config $config) {} |
|
| 15 | |||
| 16 | 7 | public function handle(array $argv): ?int |
|
| 17 | { |
||
| 18 | 7 | if (!in_array(self::KEY, $argv, true)) { |
|
| 19 | 3 | return null; |
|
| 20 | } |
||
| 21 | 4 | $this->display(); |
|
| 22 | |||
| 23 | 4 | return 0; |
|
| 24 | } |
||
| 25 | |||
| 26 | 4 | private function display(): void |
|
| 27 | { |
||
| 28 | 4 | echo 'Available sections:' . PHP_EOL; |
|
| 29 | 4 | $titles = $this->config->getSections()->getTitles(); |
|
| 30 | 4 | echo $this->formatList($titles); |
|
| 31 | 4 | $scopes = $this->config->getScopes(); |
|
| 32 | 4 | if (!empty($scopes)) { |
|
| 33 | 1 | echo PHP_EOL . 'Available scopes:' . PHP_EOL; |
|
| 34 | 1 | echo $this->formatList($scopes); |
|
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | 4 | private function formatList(array $values): string |
|
| 39 | { |
||
| 40 | 4 | $output = ''; |
|
| 41 | 4 | foreach ($values as $key => $title) { |
|
| 42 | 4 | $output .= ' ' . $key . ' - ' . $title . PHP_EOL; |
|
| 43 | } |
||
| 44 | |||
| 45 | 4 | return $output; |
|
| 46 | } |
||
| 47 | |||
| 48 | 1 | public function getHelp(): array |
|
| 52 | 1 | ]; |
|
| 53 | } |
||
| 54 | } |
||
| 55 |