ContextList::formatNode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
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 ContextList extends AbstractCommand
9
{
10
    use ConfigurationFactoryTrait;
11
12
    const TAB = '    ';
13
    const COMMAND = 'magium:configuration:list-contexts';
14
15 3
    protected function configure()
16
    {
17
        $this
18 3
            ->setName(self::COMMAND)
19 3
            ->setDescription('List contexts')
20 3
            ->setHelp("This command lists the context hierarchy")
21
        ;
22 3
    }
23
24 1
    protected function execute(InputInterface $input, OutputInterface $output)
25
    {
26 1
        $output->writeln('Context List');
27 1
        $output->writeln(['Following is list of contexts shown by inheritance', '']);
0 ignored issues
show
Documentation introduced by
array('Following is list...wn by inheritance', '') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string|object<Symfony\Co...onsole\Output\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28 1
        $factory = $this->getConfigurationFactory();
29 1
        $contextFile = $factory->getContextFile();
30 1
        $context = $contextFile->toXml();
31 1
        $output->writeln($this->formatNode('default', 'Default'));
32 1
        foreach ($context->children() as $child) {
33 1
            $this->writeNode($child, $output);
34
        }
35 1
    }
36
37 1
    protected function formatNode($id, $name = null)
38
    {
39 1
        if ($name == null) {
40 1
            return $id;
41
        }
42 1
        return sprintf('%s (%s)', $id, $name);
43
    }
44
45 1
    protected function writeNode(\SimpleXMLElement $element, OutputInterface $output, $tab = self::TAB)
46
    {
47 1
        $id = (string)$element['id'];
48 1
        $title = (string)$element['label'];
49 1
        $output->writeln($tab . $this->formatNode($id, $title));
50 1
        foreach ($element->children() as $child) {
51 1
            $this->writeNode($child, $output, $tab . self::TAB);
52
        }
53 1
    }
54
55
}
56