collectFromRuleXmlElement()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2.0625
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 8
    public function collectFromRuleXmlElement(SimpleXMLElement $ruleXmlElement)
21
    {
22 8
        if (isset($ruleXmlElement->exclude)) {
23
            $this->addExcludedSniffs($ruleXmlElement->exclude);
24
        }
25 8
    }
26
27 1
    public function addExcludedSniff(string $excludedSniffCode)
28
    {
29 1
        $this->excludedSniffCodes[] = $excludedSniffCode;
30 1
    }
31
32 7
    public function addExcludedSniffs(array $excludedSniffCodes)
33
    {
34 7
        $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 7
    }
36
37 12
    public function isSniffClassExcluded(string $sniffClassName) : bool
38
    {
39 12
        $sniffCode = SniffNaming::guessCodeByClass($sniffClassName);
40 11
        return $this->isSniffCodeExcluded($sniffCode);
41
    }
42
43 12
    public function isSniffCodeExcluded(string $sniffCode) : bool
44
    {
45 12
        return in_array($sniffCode, $this->excludedSniffCodes);
46
    }
47
}
48