Application::resolveCommandConfiguration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

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