GraphvizDumpCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A __construct() 0 6 1
A execute() 0 13 1
1
<?php
2
3
namespace BrainExe\Core\Console;
4
5
use BrainExe\Core\DependencyInjection\Rebuild;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\DependencyInjection\Dumper\GraphvizDumper;
10
use BrainExe\Core\Annotations\Command as CommandAnnotation;
11
12
/**
13
 * @CommandAnnotation
14
 * @codeCoverageIgnore
15
 */
16
class GraphvizDumpCommand extends Command
17
{
18
19
    /**
20
     * @var Rebuild
21
     */
22
    private $rebuild;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function configure()
28
    {
29
        $this->setName('graphviz:dump')
30
            ->setDescription('Dump container to graphviz');
31
    }
32
33
    /**
34
     * @param Rebuild $rebuild
35
     */
36
    public function __construct(Rebuild $rebuild)
37
    {
38
        $this->rebuild = $rebuild;
39
40
        parent::__construct();
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    protected function execute(InputInterface $input, OutputInterface $output)
47
    {
48
        $dic = $this->rebuild->buildContainer();
49
50
        $dumper  = new GraphvizDumper($dic);
0 ignored issues
show
Compatibility introduced by
$dic of type object<Symfony\Component...ncyInjection\Container> is not a sub-type of object<Symfony\Component...ction\ContainerBuilder>. It seems like you assume a child class of the class Symfony\Component\DependencyInjection\Container to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
51
        $content = $dumper->dump();
52
53
        file_put_contents(ROOT . 'cache/dic.gv', $content);
54
        exec('dot -Tpng cache/dic.gv -o cache/graph.png; rm cache/dic.gv');
55
56
        $output->writeln('PNG: <info>cache/graph.png</info>');
57
        $output->writeln('GV:  <info>cache/dic.gv</info>');
58
    }
59
}
60