|
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; |
|
|
|
|
|
|
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
|
|
|
} |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.