1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Symplify |
5
|
|
|
* Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz). |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Symplify\MultiCodingStandard\Console\Command; |
9
|
|
|
|
10
|
|
|
use Symfony\Component\Console\Command\Command; |
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
use Symfony\Component\Console\Style\StyleInterface; |
15
|
|
|
use Symplify\MultiCodingStandard\Application\Application; |
16
|
|
|
use Symplify\MultiCodingStandard\Application\Command\RunApplicationCommand; |
17
|
|
|
use Symplify\MultiCodingStandard\Configuration\MultiCsFileLoader; |
18
|
|
|
use Symplify\MultiCodingStandard\Console\Output\InfoMessagePrinter; |
19
|
|
|
use Symplify\PHP7_CodeSniffer\Console\ExitCode; |
20
|
|
|
use Throwable; |
21
|
|
|
|
22
|
|
|
final class RunCommand extends Command |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var StyleInterface |
26
|
|
|
*/ |
27
|
|
|
private $style; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Application |
31
|
|
|
*/ |
32
|
|
|
private $application; |
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var MultiCsFileLoader |
36
|
|
|
*/ |
37
|
|
|
private $multiCsFileLoader; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var InfoMessagePrinter |
41
|
|
|
*/ |
42
|
|
|
private $infoMessagePrinter; |
43
|
|
|
|
44
|
|
|
public function __construct( |
45
|
|
|
Application $application, |
46
|
|
|
StyleInterface $style, |
47
|
|
|
MultiCsFileLoader $multiCsFileLoader, |
48
|
|
|
InfoMessagePrinter $infoMessagePrinter |
49
|
|
|
) { |
50
|
|
|
parent::__construct(); |
51
|
|
|
|
52
|
|
|
$this->application = $application; |
53
|
|
|
$this->style = $style; |
54
|
|
|
$this->multiCsFileLoader = $multiCsFileLoader; |
55
|
|
|
$this->infoMessagePrinter = $infoMessagePrinter; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
protected function configure() |
62
|
|
|
{ |
63
|
|
|
$this->setName('run'); |
64
|
|
|
$this->addArgument('source', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'The path(s) to be checked.'); |
65
|
|
|
$this->addOption('fix', null, null, 'Fix found violations.'); |
66
|
|
|
$this->setDescription('Check coding standard in one or more directories.'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
73
|
|
|
{ |
74
|
|
|
try { |
75
|
|
|
$this->application->runCommand( |
76
|
|
|
$this->createRunApplicationCommandFromInput($input) |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
if ($this->infoMessagePrinter->hasSomeErrorMessages()) { |
80
|
|
|
$this->infoMessagePrinter->printFoundErrorsStatus($input->getOption('fix')); |
81
|
|
|
|
82
|
|
|
// $this->style->error( |
|
|
|
|
83
|
|
|
// sprintf( |
84
|
|
|
// 'We found some errors in "%s".', |
85
|
|
|
// implode(',', $input->getArgument('source')) |
86
|
|
|
// ) |
87
|
|
|
// ); |
88
|
|
|
|
89
|
|
|
return ExitCode::ERROR; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$this->style->success( |
93
|
|
|
sprintf( |
94
|
|
|
'Sources "%s" were checked!', |
95
|
|
|
implode(',', $input->getArgument('source')) |
96
|
|
|
) |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
return ExitCode::SUCCESS; |
100
|
|
|
} catch (Throwable $throwable) { |
101
|
|
|
if ($throwable->getMessage()) { |
102
|
|
|
$this->style->error($throwable->getMessage()); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return ExitCode::ERROR; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
private function createRunApplicationCommandFromInput(InputInterface $input) : RunApplicationCommand |
110
|
|
|
{ |
111
|
|
|
return new RunApplicationCommand( |
112
|
|
|
$input->getArgument('source'), |
113
|
|
|
$input->getOption('fix'), |
114
|
|
|
$this->multiCsFileLoader->load() |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|