1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Funivan\Cs\Console; |
4
|
|
|
|
5
|
|
|
use Funivan\Cs\Configuration\ConfigurationInterface; |
6
|
|
|
use Funivan\Cs\Configuration\CsConfiguration; |
7
|
|
|
use Funivan\Cs\FileProcessor\ReviewFileProcessor; |
8
|
|
|
use Funivan\Cs\Report\Report; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* |
14
|
|
|
*/ |
15
|
|
|
class ReviewCommand extends BaseCommand { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @inheritdoc |
19
|
|
|
*/ |
20
|
|
|
protected function configure() { |
21
|
|
|
$this->setName('review'); |
22
|
|
|
$this->setDescription('Review source code according to your code style'); |
23
|
|
|
parent::configure(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @inheritdoc |
29
|
|
|
*/ |
30
|
|
|
protected function getFileProcessor(InputInterface $input, OutputInterface $output) { |
31
|
|
|
return new ReviewFileProcessor(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @inheritdoc |
37
|
|
|
*/ |
38
|
|
|
protected function getResultState(InputInterface $input, OutputInterface $output, Report $report) { |
39
|
|
|
// show errors |
40
|
|
|
|
41
|
|
|
$isVerbose = ($output->getVerbosity() === OutputInterface::VERBOSITY_DEBUG); |
42
|
|
|
|
43
|
|
|
$output->writeln(''); |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
$errorsNum = 0; |
47
|
|
|
foreach ($report as $message) { |
48
|
|
|
$errorsNum++; |
49
|
|
|
|
50
|
|
|
$output->write('<error>'); |
51
|
|
|
$output->writeln('file : ' . $message->getFile()->getPath() . ':' . $message->getLine()); |
52
|
|
|
if ($isVerbose) { |
53
|
|
|
$output->writeln('tool : ' . $message->getTool()->getName()); |
54
|
|
|
$output->writeln('info : ' . $message->getTool()->getDescription()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$output->writeln('message : ' . $message->getText()); |
58
|
|
|
$output->writeln('</error>'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if ($errorsNum === 0) { |
62
|
|
|
$output->writeln('<info>✔ Looking good</info>'); |
63
|
|
|
return 0; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$output->writeln('<error>✘ Please fix the errors above. Errors num: ' . $errorsNum . '</error>'); |
67
|
|
|
return 1; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return ConfigurationInterface |
73
|
|
|
*/ |
74
|
|
|
protected function getDefaultConfiguration() { |
75
|
|
|
return CsConfiguration::createReviewConfiguration(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|