1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Code-Insight library. |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
8
|
|
|
* @link https://github.com/console-helpers/code-insight |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\CodeInsight\Command; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use ConsoleHelpers\CodeInsight\KnowledgeBase\KnowledgeBaseFactory; |
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Input\InputOption; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
|
20
|
|
|
class ReportCommand extends AbstractCommand |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Path to a project. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $projectPath; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Knowledge base factory. |
32
|
|
|
* |
33
|
|
|
* @var KnowledgeBaseFactory |
34
|
|
|
*/ |
35
|
|
|
private $_knowledgeBaseFactory; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
protected function configure() |
41
|
|
|
{ |
42
|
|
|
$this |
43
|
|
|
->setName('report') |
44
|
|
|
->setDescription('Analyzes project and shows the report') |
45
|
|
|
->addArgument( |
46
|
|
|
'project-path', |
47
|
|
|
InputArgument::OPTIONAL, |
48
|
|
|
'Path to project root folder (where <comment>.code-insight.json</comment> is located)', |
49
|
|
|
'.' |
50
|
|
|
) |
51
|
|
|
->addOption( |
52
|
|
|
'refresh', |
53
|
|
|
'r', |
54
|
|
|
InputOption::VALUE_NONE, |
55
|
|
|
'Refreshes database' |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Prepare dependencies. |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
protected function prepareDependencies() |
65
|
|
|
{ |
66
|
|
|
parent::prepareDependencies(); |
67
|
|
|
|
68
|
|
|
$container = $this->getContainer(); |
69
|
|
|
|
70
|
|
|
$this->_knowledgeBaseFactory = $container['knowledge_base_factory']; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
77
|
|
|
{ |
78
|
|
|
$knowledge_base = $this->_knowledgeBaseFactory->getKnowledgeBase( |
79
|
|
|
$this->getPath('project-path'), |
80
|
|
|
$this->io |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
if ( $this->io->getOption('refresh') ) { |
84
|
|
|
$knowledge_base->refresh(); |
85
|
|
|
$this->io->writeln(''); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$this->io->writeln('<comment>Results:</comment>'); |
89
|
|
|
|
90
|
|
|
foreach ( $knowledge_base->getStatistics() as $name => $value ) { |
91
|
|
|
$this->io->writeln(' * ' . $name . ': <info>' . $value . '</info>'); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
|