Completed
Push — master ( 50809e...8af631 )
by Tomáš
04:38 queued 02:05
created

Configuration   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 95
Duplicated Lines 31.58 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 10
c 5
b 0
f 2
lcom 1
cbo 2
dl 30
loc 95
ccs 25
cts 25
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getActiveSniffs() 10 10 2
A getActiveStandards() 10 10 2
A getExcludedSniffs() 10 10 2
A normalizeSniffsFromClassesToUnderscoreLowercase() 0 4 1
A ensureMultiJsFileIsLoaded() 0 6 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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