Completed
Pull Request — master (#2)
by Tomáš
03:12
created

Configuration::getActiveSniffs()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 13
ccs 5
cts 6
cp 0.8333
rs 9.4285
cc 3
eloc 6
nc 4
nop 0
crap 3.0416
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\Configuration;
9
10
use Symplify\MultiCodingStandard\Contract\CodeSniffer\Naming\SniffNamingInterface;
11
use Symplify\MultiCodingStandard\Contract\Configuration\ConfigurationInterface;
12
use Symplify\MultiCodingStandard\Contract\Configuration\MultiCsFileLoaderInterface;
13
14
final class Configuration implements ConfigurationInterface
15
{
16
    /**
17
     * @var MultiCsFileLoaderInterface
18
     */
19
    private $multiCsFileLoader;
20
21
    /**
22
     * @var SniffNamingInterface
23
     */
24
    private $sniffNaming;
25
26
    /**
27
     * @var null|array
28
     */
29
    private $multiCsFile;
30
31 4
    public function __construct(MultiCsFileLoaderInterface $multiCsFileLoader, SniffNamingInterface $sniffNaming)
32
    {
33 4
        $this->multiCsFileLoader = $multiCsFileLoader;
34 4
        $this->sniffNaming = $sniffNaming;
35 4
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 4
    public function getActiveSniffs()
41
    {
42 4
        if ($this->multiCsFile === null) {
43 4
            $this->multiCsFile = $this->multiCsFileLoader->load();
44
        }
45
46 4
        if (isset($this->multiCsFile['sniffs'])) {
47 4
            return $this->normalizeSniffsFromClassesToUnderscoreLowercase($this->multiCsFile['sniffs']);
48
        }
49
50
51
        return [];
52
    }
53
54
    /**
55
     * @return string[]
56
     */
57 4
    private function normalizeSniffsFromClassesToUnderscoreLowercase(array $sniffs)
58
    {
59 4
        return $this->sniffNaming->detectUnderscoreLowercaseFromSniffClasses($sniffs);
60
    }
61
}
62