Completed
Push — master ( 74ff7b...2fd8e1 )
by Tomáš
03:25
created

SingleSniffFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 43
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A create() 0 9 2
A setCustomSniffPropertyValues() 0 9 2
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\Factory;
9
10
use PHP_CodeSniffer\Sniffs\Sniff;
11
use Symplify\PHP7_CodeSniffer\Sniff\Xml\DataCollector\SniffPropertyValueDataCollector;
12
use Symplify\PHP7_CodeSniffer\Sniff\Xml\DataCollector\ExcludedSniffDataCollector;
13
14
final class SingleSniffFactory
15
{
16
    /**
17
     * @var ExcludedSniffDataCollector
18
     */
19
    private $excludedSniffDataCollector;
20
21
    /**
22
     * @var SniffPropertyValueDataCollector
23
     */
24
    private $sniffPropertyValueDataCollector;
25
26 15
    public function __construct(
27
        ExcludedSniffDataCollector $excludedSniffDataCollector,
28
        SniffPropertyValueDataCollector $customSniffPropertyDataCollector
29
    ) {
30 15
        $this->excludedSniffDataCollector = $excludedSniffDataCollector;
31 15
        $this->sniffPropertyValueDataCollector = $customSniffPropertyDataCollector;
32 15
    }
33
34
    /**
35
     * @return Sniff|null
36
     */
37 10
    public function create(string $sniffClassName)
38
    {
39 10
        if ($this->excludedSniffDataCollector->isSniffClassExcluded($sniffClassName)) {
40 1
            return null;
41
        }
42
43 9
        $sniff = new $sniffClassName;
44 9
        return $this->setCustomSniffPropertyValues($sniff);
45
    }
46
47 9
    private function setCustomSniffPropertyValues(Sniff $sniff) : Sniff
48
    {
49 9
        $sniffPropertyValues = $this->sniffPropertyValueDataCollector->getForSniff($sniff);
50 9
        foreach ($sniffPropertyValues as $property => $value) {
51 1
            $sniff->$property = $value;
52
        }
53
54 9
        return $sniff;
55
    }
56
}
57