|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Inspector\Application\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Inspector\Application\Command; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Inspector\Application\Service\AnalyzerService; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
|
|
12
|
|
|
class InspectCommand extends Command |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
protected $name = 'inspect'; |
|
16
|
|
|
|
|
17
|
|
|
protected $description = 'Inspects and analyzes the source code'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var AnalyzerService |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $analyzerService; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param AnalyzerService $analyzerService |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(AnalyzerService $analyzerService) |
|
28
|
|
|
{ |
|
29
|
|
|
parent::__construct(); |
|
30
|
|
|
|
|
31
|
|
|
$this->analyzerService = $analyzerService; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @return array |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function getArguments() |
|
38
|
|
|
{ |
|
39
|
|
|
return [ |
|
40
|
|
|
['path', InputArgument::REQUIRED, 'Source path to inspect'] |
|
41
|
|
|
]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return array |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function getOptions() |
|
48
|
|
|
{ |
|
49
|
|
|
return [ |
|
50
|
|
|
['generate-report', 'g', InputOption::VALUE_NONE, 'Generates analysis report'], |
|
51
|
|
|
['path', 'p', InputOption::VALUE_OPTIONAL, 'Path to generate the report', getcwd()], |
|
52
|
|
|
[ |
|
53
|
|
|
'show', |
|
54
|
|
|
'w', |
|
55
|
|
|
InputOption::VALUE_NONE, |
|
56
|
|
|
'When used with \'--generate-report\' option runs the Web server to show the generated report. ' |
|
57
|
|
|
], |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param InputInterface $input |
|
63
|
|
|
* @param OutputInterface $output |
|
64
|
|
|
* @return int|null|void |
|
65
|
|
|
* @throws \Exception |
|
66
|
|
|
*/ |
|
67
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
68
|
|
|
{ |
|
69
|
|
|
$path = $input->getArgument('path'); |
|
70
|
|
|
$options = $input->getOptions(); |
|
71
|
|
|
|
|
72
|
|
|
if (!$options['quiet']) { |
|
73
|
|
|
$output->writeln("\n" . '<info>Inspecting</info> ' . $path); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$feedback = $this->analyzerService->analyze($path, $options); |
|
77
|
|
|
$output->writeln($feedback . "\n"); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|