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

ExcludedSniffDataCollector::addExcludedSniff()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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