Completed
Pull Request — master (#2)
by Tomáš
02:50
created

Configuration::normalizeSniffsFromClassesToNames()   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
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
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\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 array
28
     */
29
    private $multiCsFile;
30
31 5
    public function __construct(MultiCsFileLoaderInterface $multiCsFileLoader, SniffNamingInterface $sniffNaming)
32
    {
33 5
        $this->multiCsFileLoader = $multiCsFileLoader;
34 5
        $this->sniffNaming = $sniffNaming;
35 5
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 5
    public function getActiveSniffs()
41
    {
42 5
        $this->ensureMultiJsFileIsLoaded();
43
44 5
        if (isset($this->multiCsFile['sniffs'])) {
45 3
            return $this->normalizeSniffsFromClassesToUnderscoreLowercase($this->multiCsFile['sniffs']);
46
        }
47
48 2
        return [];
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 5
    public function getActiveStandards()
55
    {
56 5
        $this->ensureMultiJsFileIsLoaded();
57
58 5
        if (isset($this->multiCsFile['standards'])) {
59 2
            return $this->multiCsFile['standards'];
60
        }
61
62 3
        return [];
63
    }
64
65
    /**
66
     * @return string[]
67
     */
68 3
    private function normalizeSniffsFromClassesToUnderscoreLowercase(array $sniffs)
69
    {
70 3
        return $this->sniffNaming->detectUnderscoreLowercaseFromSniffClasses($sniffs);
71
    }
72
73 5
    private function ensureMultiJsFileIsLoaded()
74
    {
75 5
        if ($this->multiCsFile === null) {
76 5
            $this->multiCsFile = $this->multiCsFileLoader->load();
77
        }
78 5
    }
79
}
80