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

InfoCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 29.4%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 31
ccs 5
cts 17
cp 0.294
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 0 14 3
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