Completed
Pull Request — master (#10)
by Tomáš
24:14
created

RunCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 2
cbo 3
dl 0
loc 65
ccs 0
cts 22
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A configure() 0 7 1
A execute() 0 21 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\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'));
0 ignored issues
show
Bug introduced by
The method resolveSource() does not exist on Symplify\PHP7_CodeSniffe...n\ConfigurationResolver. Did you maybe mean resolve()?

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.

Loading history...
67
        $isFixer = $input->getOption('fix');
68
69
        try {
70
            $this->php7CodeSniffer->runForSource($source, $isFixer);
0 ignored issues
show
Bug introduced by
The method runForSource() does not seem to exist on object<Symplify\PHP7_CodeSniffer\Php7CodeSniffer>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

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