Completed
Push — master ( 3b5f38...c5ceed )
by Tomáš
04:59
created

getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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) {
0 ignored issues
show
Bug introduced by
The class Symplify\PHP7_CodeSniffe...sole\Command\FixCommand does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to 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 require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
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