Completed
Push — master ( 50809e...8af631 )
by Tomáš
04:38 queued 02:05
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 string
18
     */
19
    const STANDARDS = 'standards';
20
21
    /**
22
     * @var string
23
     */
24
    const SNIFFS = 'sniffs';
25
    
26
    /**
27
     * @var string
28
     */
29
    const EXCLUDED_SNIFFS = 'exclude-sniffs';
30
    
31
    /**
32
     * @var MultiCsFileLoaderInterface
33
     */
34
    private $multiCsFileLoader;
35
36
    /**
37
     * @var SniffNamingInterface
38
     */
39
    private $sniffNaming;
40
41
    /**
42
     * @var array
43
     */
44
    private $multiCsFile;
45
46 5
    public function __construct(MultiCsFileLoaderInterface $multiCsFileLoader, SniffNamingInterface $sniffNaming)
47
    {
48 5
        $this->multiCsFileLoader = $multiCsFileLoader;
49 5
        $this->sniffNaming = $sniffNaming;
50 5
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 5 View Code Duplication
    public function getActiveSniffs()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57 5
        $this->ensureMultiJsFileIsLoaded();
58
59 5
        if (isset($this->multiCsFile[self::SNIFFS])) {
60 3
            return $this->normalizeSniffsFromClassesToUnderscoreLowercase($this->multiCsFile[self::SNIFFS]);
61
        }
62
63 2
        return [];
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 5 View Code Duplication
    public function getActiveStandards()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71 5
        $this->ensureMultiJsFileIsLoaded();
72
73 5
        if (isset($this->multiCsFile[self::STANDARDS])) {
74 2
            return $this->multiCsFile[self::STANDARDS];
75
        }
76
77 3
        return [];
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 2 View Code Duplication
    public function getExcludedSniffs()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85 2
        $this->ensureMultiJsFileIsLoaded();
86
87 2
        if (isset($this->multiCsFile[self::EXCLUDED_SNIFFS])) {
88 1
            return $this->multiCsFile[self::EXCLUDED_SNIFFS];
89
        }
90
91 1
        return [];
92
    }
93
94
    /**
95
     * @return string[]
96
     */
97 3
    private function normalizeSniffsFromClassesToUnderscoreLowercase(array $sniffs)
98
    {
99 3
        return $this->sniffNaming->detectUnderscoreLowercaseFromSniffClasses($sniffs);
100
    }
101
102 5
    private function ensureMultiJsFileIsLoaded()
103
    {
104 5
        if ($this->multiCsFile === null) {
105 5
            $this->multiCsFile = $this->multiCsFileLoader->load();
106
        }
107 5
    }
108
}
109