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

Configuration   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 8
c 4
b 0
f 1
lcom 1
cbo 2
dl 0
loc 66
ccs 20
cts 20
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A normalizeSniffsFromClassesToUnderscoreLowercase() 0 4 1
A ensureMultiJsFileIsLoaded() 0 6 2
A getActiveSniffs() 0 10 2
A getActiveStandards() 0 10 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