Legend   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 19
c 1
b 0
f 0
dl 0
loc 42
ccs 22
cts 22
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A getHelp() 0 4 1
A display() 0 9 2
A formatList() 0 8 2
A handle() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Vasoft\VersionIncrement\Core;
6
7
use Vasoft\VersionIncrement\Config;
8
use Vasoft\VersionIncrement\Contract\ApplicationHandlerInterface;
9
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
49
    {
50 1
        return [
51 1
            new HelpRow(Help::SECTION_KEYS, self::KEY, 'Show list of sections'),
52 1
        ];
53
    }
54
}
55