ConfigurationListKeys::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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