|
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\PHP7_CodeSniffer\Configuration\EventSubscriber; |
|
9
|
|
|
|
|
10
|
|
|
use Symfony\Component\Console\ConsoleEvents; |
|
11
|
|
|
use Symfony\Component\Console\Event\ConsoleCommandEvent; |
|
12
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
13
|
|
|
use Symplify\PHP7_CodeSniffer\Configuration\Configuration; |
|
14
|
|
|
use Symplify\PHP7_CodeSniffer\Console\Command\FixCommand; |
|
15
|
|
|
|
|
16
|
|
|
final class ResolveConfigurationEventSubscriber implements EventSubscriberInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var Configuration |
|
20
|
|
|
*/ |
|
21
|
|
|
private $configuration; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct(Configuration $configuration) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->configuration = $configuration; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function getSubscribedEvents() |
|
32
|
|
|
{ |
|
33
|
|
|
return [ConsoleEvents::COMMAND => 'onConsoleRun']; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function onConsoleRun(ConsoleCommandEvent $consoleCommandEvent) |
|
37
|
|
|
{ |
|
38
|
|
|
$input = $consoleCommandEvent->getInput(); |
|
39
|
|
|
|
|
40
|
|
|
$arguments = array_merge($input->getArguments(), $input->getOptions()); |
|
41
|
|
|
$arguments = $this->detectFixerAndSetIt($consoleCommandEvent, $arguments); |
|
42
|
|
|
$arguments = $this->removeSystemArguments($arguments); |
|
43
|
|
|
|
|
44
|
|
|
$this->configuration->resolveFromArray($arguments); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
private function detectFixerAndSetIt(ConsoleCommandEvent $consoleCommandEvent, array $arguments) : array |
|
48
|
|
|
{ |
|
49
|
|
|
$command = $consoleCommandEvent->getCommand(); |
|
50
|
|
|
if ($command instanceof FixCommand) { |
|
|
|
|
|
|
51
|
|
|
$arguments['isFixer'] = true; |
|
52
|
|
|
return $arguments; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $arguments; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
private function removeSystemArguments(array $arguments) : array |
|
59
|
|
|
{ |
|
60
|
|
|
$systemArguments = ['help', 'command', 'version', 'command_name', 'format', 'raw']; |
|
61
|
|
|
foreach ($systemArguments as $systemArgument) { |
|
62
|
|
|
unset($arguments[$systemArgument]); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $arguments; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.