DebugConfigCommand::execute()   A
last analyzed

Complexity

Conditions 6
Paths 13

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 14
c 1
b 0
f 0
nc 13
nop 2
dl 0
loc 22
rs 9.2222
1
<?php
2
3
namespace BenTools\MercurePHP\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Console\Style\SymfonyStyle;
9
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
10
11
final class DebugConfigCommand extends Command
12
{
13
    const CONFIGURATION_KEYS = [
14
        'addr',
15
        'transport_url',
16
        'storage_url',
17
        'metrics_url',
18
        'cors_allowed_origins',
19
        'publish_allowed_origins',
20
        'jwt_key',
21
        'jwt_algorithm',
22
        'publisher_jwt_key',
23
        'publisher_jwt_algorithm',
24
        'subscriber_jwt_key',
25
        'subscriber_jwt_algorithm',
26
        'allow_anonymous',
27
    ];
28
29
    protected static $defaultName = 'mercure:debug:config';
30
31
    private ParameterBagInterface $params;
32
    private ?string $addr;
33
34
    public function __construct(ParameterBagInterface $params, ?string $addr = null)
35
    {
36
        parent::__construct();
37
        $this->params = $params;
38
        $this->addr = $addr;
39
    }
40
41
    protected function execute(InputInterface $input, OutputInterface $output): int
42
    {
43
        $io = new SymfonyStyle($input, $output);
44
        $keys = self::CONFIGURATION_KEYS;
45
        $rows = [];
46
        foreach ($keys as $key) {
47
            $value = $this->params->get($key);
48
            if (null === $value) {
49
                $value = '<fg=yellow>null</>';
50
            }
51
            if (\is_bool($value)) {
52
                $value = $value ? '<fg=green>true</>' : '<fg=red>false</>';
53
            }
54
            if ('' === $value) {
55
                $value = '<fg=white>\'\'</>';
56
            }
57
            $rows[] = [$key, $value];
58
        }
59
60
        $io->table(['Key', 'Value'], $rows);
61
62
        return self::SUCCESS;
63
    }
64
}
65