Completed
Push — master ( 64bec4...eaf10f )
by Tomáš
05:07
created

Application::runCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1.0046

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 1.0046
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\Application;
9
10
use Symplify\PHP7_CodeSniffer\Application\Command\RunApplicationCommand;
11
use Symplify\PHP7_CodeSniffer\Configuration\ConfigurationResolver;
12
use Symplify\PHP7_CodeSniffer\EventDispatcher\SniffDispatcher;
13
use Symplify\PHP7_CodeSniffer\Exception\AnySniffMissingException;
14
use Symplify\PHP7_CodeSniffer\File\Provider\FilesProvider;
15
use Symplify\PHP7_CodeSniffer\Legacy\LegacyConfiguration;
16
use Symplify\PHP7_CodeSniffer\Sniff\SniffSetFactory;
17
use Symplify\PHP7_CodeSniffer\Sniff\Xml\DataCollector\ExcludedSniffDataCollector;
18
19
final class Application
20
{
21
    /**
22
     * @var SniffDispatcher
23
     */
24
    private $sniffDispatcher;
25
26
    /**
27
     * @var FilesProvider
28
     */
29
    private $filesProvider;
30
31
    /**
32
     * @var SniffSetFactory
33
     */
34
    private $sniffSetFactory;
35
36
    /**
37
     * @var ExcludedSniffDataCollector
38
     */
39
    private $excludedSniffDataCollector;
40
41
    /**
42
     * @var ConfigurationResolver
43
     */
44
    private $configurationResolver;
45
46
    /**
47
     * @var FileProcessor
48
     */
49
    private $fileProcessor;
50
51 1
    public function __construct(
52
        SniffDispatcher $sniffDispatcher,
53
        FilesProvider $sourceFilesProvider,
54
        SniffSetFactory $sniffFactory,
55
        ExcludedSniffDataCollector $excludedSniffDataCollector,
56
        ConfigurationResolver $configurationResolver,
57
        FileProcessor $fileProcessor
58
    ) {
59 1
        $this->sniffDispatcher = $sniffDispatcher;
60 1
        $this->filesProvider = $sourceFilesProvider;
61 1
        $this->sniffSetFactory = $sniffFactory;
62 1
        $this->excludedSniffDataCollector = $excludedSniffDataCollector;
63 1
        $this->configurationResolver = $configurationResolver;
64 1
        $this->fileProcessor = $fileProcessor;
65
66 1
        LegacyConfiguration::setup();
67 1
    }
68
69 1
    public function runCommand(RunApplicationCommand $command)
70
    {
71 1
        $command = $this->resolveCommandConfiguration($command);
72
73 1
        $this->excludedSniffDataCollector->addExcludedSniffs($command->getExcludedSniffs());
74
75 1
        $this->createAndRegisterSniffsToSniffDispatcher($command->getStandards(), $command->getSniffs());
76
77 1
        $this->runForSource($command->getSource(), $command->isFixer());
78
    }
79
80 1
    private function createAndRegisterSniffsToSniffDispatcher(array $standards, array $extraSniffs)
81
    {
82 1
        $sniffs = $this->sniffSetFactory->createFromStandardsAndSniffs($standards, $extraSniffs);
83 1
        $this->sniffDispatcher->addSniffListeners($sniffs);
84 1
    }
85
86 1
    private function runForSource(array $source, bool $isFixer)
87
    {
88 1
        $files = $this->filesProvider->getFilesForSource($source, $isFixer);
89
        $this->fileProcessor->processFiles($files, $isFixer);
90
    }
91
92 1
    private function resolveCommandConfiguration(RunApplicationCommand $command) : RunApplicationCommand
93
    {
94 1
        return new RunApplicationCommand(
95 1
            $command->getSource(),
96 1
            $this->configurationResolver->resolve('standards', $command->getStandards()),
97 1
            $this->configurationResolver->resolve('sniffs', $command->getSniffs()),
98 1
            $this->configurationResolver->resolve('sniffs', $command->getExcludedSniffs()),
99 1
            $command->isFixer()
100
        );
101
    }
102
}
103