Passed
Push — master ( 62679a...2b0c72 )
by Gerard van
07:11
created

InfoCommand::execute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 0
cts 12
cp 0
rs 9.4285
cc 3
eloc 10
nc 2
nop 2
crap 12
1
<?php
2
/**
3
 * @author Gerard van Helden <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
namespace Zicht\Tool\Command;
7
8
use Symfony\Component\Console\Input;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Input\InputInterface;
11
12
/**
13
 * Command to show some info about the Z container
14
 */
15
class InfoCommand extends BaseCommand
16
{
17
    /**
18
     * @{inheritDoc}
19
     */
20 1
    protected function configure()
21
    {
22 1
        $this
23 1
            ->setName('z:info')
24 1
            ->setDescription("Prints useful info about the current Z environment")
25
        ;
26 1
    }
27
28
    /**
29
     * @{inheritDoc}
30
     */
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $sourceFiles = $this->getContainer()->get(array('z', 'sources'));
34
        $output->writeln('Z executable used: ' . ZBIN);
35
        if (count($sourceFiles)) {
36
            $output->writeln('Loaded source files');
37
            foreach ($sourceFiles as $file) {
0 ignored issues
show
Bug introduced by
The expression $sourceFiles of type string|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
38
                $output->writeln(" - " . $file);
39
            }
40
        } else {
41
            $output->writeln('No source files loaded');
42
        }
43
        $output->writeln('Compiled file: ' . $this->getContainer()->get(array('z', 'cache_file')));
44
    }
45
}
46