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\Command; |
9
|
|
|
|
10
|
|
|
use Exception; |
11
|
|
|
use PHP_CodeSniffer; |
12
|
|
|
use Symfony\Component\Console\Command\Command; |
13
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
use Symfony\Component\Console\Style\StyleInterface; |
17
|
|
|
use Symplify\MultiCodingStandard\Console\ExitCode; |
18
|
|
|
use Symplify\PHP7_CodeSniffer\Configuration\ConfigurationResolver; |
19
|
|
|
use Symplify\PHP7_CodeSniffer\Php7CodeSniffer; |
20
|
|
|
|
21
|
|
|
final class RunCommand extends Command |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var Php7CodeSniffer |
25
|
|
|
*/ |
26
|
|
|
private $php7CodeSniffer; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var StyleInterface |
30
|
|
|
*/ |
31
|
|
|
private $style; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var ConfigurationResolver |
35
|
|
|
*/ |
36
|
|
|
private $configurationResolver; |
37
|
|
|
|
38
|
|
|
public function __construct( |
39
|
|
|
Php7CodeSniffer $php7CodeSniffer, |
40
|
|
|
StyleInterface $style, |
41
|
|
|
ConfigurationResolver $configurationResolver |
42
|
|
|
) { |
43
|
|
|
parent::__construct(); |
44
|
|
|
|
45
|
|
|
$this->php7CodeSniffer = $php7CodeSniffer; |
46
|
|
|
$this->style = $style; |
47
|
|
|
$this->configurationResolver = $configurationResolver; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
protected function configure() |
54
|
|
|
{ |
55
|
|
|
$this->setName('run'); |
56
|
|
|
$this->addArgument('source', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'The path(s) to be checked.'); |
57
|
|
|
$this->addOption('fix', null, null, 'Fix found violations.'); |
58
|
|
|
$this->setDescription('Check coding standard in one or more directories.'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
65
|
|
|
{ |
66
|
|
|
$source = $this->configurationResolver->resolveSource($input->getArgument('source')); |
|
|
|
|
67
|
|
|
$isFixer = $input->getOption('fix'); |
68
|
|
|
|
69
|
|
|
try { |
70
|
|
|
$this->php7CodeSniffer->runForSource($source, $isFixer); |
|
|
|
|
71
|
|
|
|
72
|
|
|
// todo: php-cs-fixer |
73
|
|
|
|
74
|
|
|
$this->style->success( |
75
|
|
|
sprintf('Sources "%s" were checked!', implode(',', $source)) |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
return ExitCode::SUCCESS; |
79
|
|
|
} catch (Exception $exception) { |
80
|
|
|
$this->style->error($exception->getMessage()); |
81
|
|
|
|
82
|
|
|
return ExitCode::ERROR; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.