Passed
Push — develop ( 74ec49...5c7a50 )
by Kevin
12:14 queued 08:09
created

ConfigurationListKeys::execute()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 29
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 4.0015

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 29
ccs 21
cts 22
cp 0.9545
rs 8.5806
cc 4
eloc 22
nc 5
nop 2
crap 4.0015
1
<?php
2
3
namespace Magium\Configuration\Console\Command;
4
5
use Magium\Configuration\Config\Config;
6
use Magium\Configuration\MagiumConfigurationFactory;
7
use Magium\Configuration\MagiumConfigurationFactoryInterface;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class ConfigurationListKeys extends Command
14
{
15
    use ConfigurationFactoryTrait;
16
17
    const COMMAND = 'magium:configuration:list-keys';
18
19
    const INITIAL_MESSAGE = 'Valid configuration keys';
20
21 3
    protected function configure()
22
    {
23
        $this
24 3
            ->setName(self::COMMAND)
25 3
            ->setDescription('List configuration settings')
26 3
            ->setHelp("This command lists all of the configuration setting options")
27
        ;
28 3
    }
29
30 1
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32 1
        $factory = $this->getConfigurationFactory();
33 1
        $builder = $factory->getBuilder();
34 1
        $merged = $builder->getMergedStructure();
35 1
        $merged->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration');
36 1
        $elements = $merged->xpath('//s:element');
37 1
        $output->writeln(self::INITIAL_MESSAGE);
38 1
        foreach ($elements as $element) {
39 1
            $elementId = (string)$element['id'];
40 1
            $parent = $element->xpath('..');
41 1
            $groupId = (string)$parent[0]['id'];
42 1
            $parent = $parent[0]->xpath('..');
43 1
            $sectionId = (string)$parent[0]['id'];
44 1
            $default = '';
45 1
            if (isset($element->value)) {
46 1
                $default = sprintf(' (default: %s) ', (string)$element->value);
47
            }
48 1
            if (isset($element->description)) {
49 1
                $description = sprintf("%s\n        (%s)", $default, (string)$element->description);
50
            } else {
51
                $description = $default;
52
            }
53
54 1
            $out = sprintf("%s/%s/%s%s\n", $sectionId, $groupId, $elementId, $description);
55 1
            $output->writeln($out);
56
57
        }
58 1
    }
59
60
}
61