Completed
Push — master ( 393329...74ff7b )
by Tomáš
10:49
created

ExcludedSniffDataCollector   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 35
ccs 14
cts 15
cp 0.9333
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A collectFromRuleXmlElement() 0 6 2
A addExcludedSniff() 0 4 1
A addExcludedSniffs() 0 4 1
A isSniffClassExcluded() 0 5 1
A isSniffCodeExcluded() 0 4 1
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\PHP7_CodeSniffer\Sniff\Xml\DataCollector;
9
10
use SimpleXMLElement;
11
use Symplify\PHP7_CodeSniffer\Sniff\Naming\SniffNaming;
12
13
final class ExcludedSniffDataCollector
14
{
15
    /**
16
     * @var string[]
17
     */
18
    private $excludedSniffCodes = [];
19
20 6
    public function collectFromRuleXmlElement(SimpleXMLElement $ruleXmlElement)
21
    {
22 6
        if (isset($ruleXmlElement->exclude)) {
23
            $this->addExcludedSniffs($ruleXmlElement->exclude);
24
        }
25 6
    }
26
27 1
    public function addExcludedSniff(string $excludedSniffCode)
28
    {
29 1
        $this->excludedSniffCodes[] = $excludedSniffCode;
30 1
    }
31
32 6
    public function addExcludedSniffs(array $excludedSniffCodes)
33
    {
34 6
        $this->excludedSniffCodes = array_merge($this->excludedSniffCodes, $excludedSniffCodes);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_merge($this->exclu...s, $excludedSniffCodes) of type array is incompatible with the declared type array<integer,string> of property $excludedSniffCodes.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35 6
    }
36
37 9
    public function isSniffClassExcluded(string $sniffClassName) : bool
38
    {
39 9
        $sniffCode = SniffNaming::guessCodeByClass($sniffClassName);
40 8
        return $this->isSniffCodeExcluded($sniffCode);
41
    }
42
43 9
    public function isSniffCodeExcluded(string $sniffCode) : bool
44
    {
45 9
        return in_array($sniffCode, $this->excludedSniffCodes);
46
    }
47
}
48