Completed
Push — master ( 4d96cc...d35fc1 )
by Tomáš
04:03 queued 01:56
created

Configuration   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 87
Duplicated Lines 22.99 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 3
Metric Value
wmc 9
c 6
b 0
f 3
lcom 1
cbo 2
dl 20
loc 87
ccs 23
cts 23
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getActiveStandards() 10 10 2
A getExcludedSniffs() 10 10 2
A getActiveSniffs() 0 10 2
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 10
    public function __construct(MultiCsFileLoaderInterface $multiCsFileLoader, SniffNamingInterface $sniffNaming)
47
    {
48 10
        $this->multiCsFileLoader = $multiCsFileLoader;
49 10
        $this->sniffNaming = $sniffNaming;
50 10
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 8
    public function getActiveSniffs()
56
    {
57 8
        $this->ensureMultiJsFileIsLoaded();
58
59 8
        if (isset($this->multiCsFile[self::SNIFFS])) {
60 5
            return $this->sniffNaming->detectUnderscoreLowercaseFromSniffClassesOrNames($this->multiCsFile[self::SNIFFS]);
61
        }
62
63 3
        return [];
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 8 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 8
        $this->ensureMultiJsFileIsLoaded();
72
73 8
        if (isset($this->multiCsFile[self::STANDARDS])) {
74 3
            return $this->multiCsFile[self::STANDARDS];
75
        }
76
77 5
        return [];
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 4 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 4
        $this->ensureMultiJsFileIsLoaded();
86
87 4
        if (isset($this->multiCsFile[self::EXCLUDED_SNIFFS])) {
88 2
            return $this->multiCsFile[self::EXCLUDED_SNIFFS];
89
        }
90
91 2
        return [];
92
    }
93
94 10
    private function ensureMultiJsFileIsLoaded()
95
    {
96 10
        if ($this->multiCsFile === null) {
97 10
            $this->multiCsFile = $this->multiCsFileLoader->load();
98
        }
99 10
    }
100
}
101