Test Failed
Push — develop ( 7fb7cc...c3d980 )
by nguereza
02:34
created

ConfigCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 4
rs 10
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;
10
11
use Platine\Config\Config;
12
use Platine\Console\Command\Command;
13
use Platine\Framework\App\Application;
14
15
/**
16
 * Description of ConfigCommand
17
 *
18
 * @author tony
19
 */
20
class ConfigCommand extends Command
21
{
22
23
    protected Application $application;
24
25
    /**
26
     *
27
     */
28
    public function __construct(Application $application)
29
    {
30
        parent::__construct('config', 'Command to manage configuration');
31
        $this->setAlias('c');
32
33
        $this->addArgument('list', 'List the configuration');
34
        $this->addOption('-t|--type', 'Configuration type', 'app', true);
35
36
        $this->application = $application;
37
    }
38
39
    public function execute()
40
    {
41
        if ($this->getArgumentValue('list')) {
42
            $this->showConfigList();
43
        }
44
    }
45
46
    protected function showConfigList(): void
47
    {
48
        $writer = $this->io()->writer();
49
        /** @template T @var Config<T> $config */
50
        $config = $this->application->get(Config::class);
51
        $type = $this->getOptionValue('type');
52
53
        $writer->blackBgBlue(sprintf('Show configuration for [%s]', $type), true)->eol();
54
55
        $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

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