Run::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Solidifier\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Solidifier\Application;
10
use Symfony\Component\Console\Input\InputOption;
11
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
12
13
class Run extends Command
14
{
15
    private
16
        $container;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $container.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
17
    
18
    public function __construct()
19
    {
20
        parent::__construct();
21
        
22
        $this->container = new Application();
23
    }
24
    
25
    protected function configure()
26
    {
27
        $this->setName('run')
28
            ->setDescription('Check rules')
29
            ->addArgument('src', InputArgument::REQUIRED, 'sources to parse')
30
            ->addOption('htmlReport', null, InputOption::VALUE_REQUIRED, 'HTML report filename');
31
    }
32
    
33
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35
        $this->configureOutputs($input, $output);
36
        
37
        $this->container['filesystem.path'] = $input->getArgument('src');
38
        
39
        $analyzer = $this->container['analyzer'];
40
        $analyzer->run();
41
    }
42
    
43
    private function configureOutputs(InputInterface $input, OutputInterface $output)
44
    {
45
        $dispatcher = $this->container['event.dispatcher'];
46
47
        $this->enableConsoleOutput($dispatcher, $output);
48
        $this->enableHtmlReport($dispatcher, $input->getOption('htmlReport'));
49
    }
50
    
51
    private function enableConsoleOutput(EventDispatcherInterface $dispatcher, OutputInterface $output)
52
    {
53
        $console = $this->container['subscriber.console'];
54
        $console->setOutput($output);
55
        $dispatcher->addSubscriber($console);
56
    }
57
    
58
    private function enableHtmlReport(EventDispatcherInterface $dispatcher, $htmlReportFilename)
59
    {
60
        if($htmlReportFilename !== null)
61
        {
62
            $html = $this->container['subscriber.html'];
63
            $html->setReportFilename($htmlReportFilename);
64
            
65
            $dispatcher->addSubscriber($html);
66
        }
67
    }
68
}