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

Configuration::ensureMultiJsFileIsLoaded()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
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 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
        $this->ensureMultiJsFileIsLoaded();
43
44 4
        if (isset($this->multiCsFile['sniffs'])) {
45 4
            return $this->normalizeSniffsFromClassesToUnderscoreLowercase($this->multiCsFile['sniffs']);
46
        }
47
48
        return [];
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 4
    public function getActiveStandards()
55
    {
56 4
        $this->ensureMultiJsFileIsLoaded();
57
58 4
        if (isset($this->multiCsFile['standards'])) {
59 4
            return $this->multiCsFile['standards'];
60
        }
61
62
        return [];
63
    }
64
65
    /**
66
     * @return string[]
67
     */
68 4
    private function normalizeSniffsFromClassesToUnderscoreLowercase(array $sniffs)
69
    {
70 4
        return $this->sniffNaming->detectUnderscoreLowercaseFromSniffClasses($sniffs);
71
    }
72
73 4
    private function ensureMultiJsFileIsLoaded()
74
    {
75 4
        if ($this->multiCsFile === null) {
76 4
            $this->multiCsFile = $this->multiCsFileLoader->load();
77
        }
78 4
    }
79
}
80