Test Failed
Push — develop ( 50f9bb...e90cf2 )
by nguereza
02:33
created

ConfigCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 4 2
A __construct() 0 9 1
A showConfigList() 0 29 3
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Platine\Framework\Demo\Command;
10
11
use Platine\Config\Config;
12
use Platine\Console\Command\Command;
13
use Platine\Framework\App\Application;
14
use Platine\Stdlib\Helper\Str;
15
16
/**
17
 * Description of ConfigCommand
18
 *
19
 * @author tony
20
 */
21
class ConfigCommand extends Command
22
{
23
24
    protected Application $application;
25
26
    /**
27
     *
28
     */
29
    public function __construct(Application $application)
30
    {
31
        parent::__construct('config', 'Command to manage configuration');
32
        $this->setAlias('c');
33
34
        $this->addArgument('list', 'List the configuration');
35
        $this->addOption('-t|--type', 'Configuration type', 'app', true);
36
37
        $this->application = $application;
38
    }
39
40
    public function execute()
41
    {
42
        if ($this->getArgumentValue('list')) {
43
            $this->showConfigList();
44
        }
45
    }
46
47
    protected function showConfigList(): void
48
    {
49
        $writer = $this->io()->writer();
50
        /** @template T @var Config<T> $config */
51
        $config = $this->application->get(Config::class);
52
        $type = $this->getOptionValue('type');
53
54
        $writer->blackBgBlue(sprintf('Show configuration for [%s]', $type), true)->eol();
55
56
        $items = (array) $config->get($type, []);
0 ignored issues
show
Bug introduced by
It seems like $type can also be of type null; however, parameter $key of Platine\Config\Config::get() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
        $items = (array) $config->get(/** @scrutinizer ignore-type */ $type, []);
Loading history...
57
        /** @var array<int, array<int, array<string, string>>> $rows*/
58
        $rows = [];
59
        foreach ($items as $name => $value) {
60
            $valueStr = Str::stringify($value);
61
            if (is_int($name)) {
62
                $rows[] = [
63
                    'value' => $valueStr
64
                ];
65
            } else {
66
                $rows[] = [
67
                    'name' => $name,
68
                    'value' => $valueStr
69
                ];
70
            }
71
        }
72
73
        $writer->table($rows);
74
75
        $writer->green('Command finished successfully')->eol();
76
    }
77
}
78