Completed
Branch master (c5ceed)
by Tomáš
33:54 queued 13:17
created

ReferenceNormalizer   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 3
dl 0
loc 68
ccs 21
cts 24
cp 0.875
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A normalize() 0 10 2
A isRulesetReference() 0 8 2
A isStandardReference() 0 9 2
A isSniffFileReference() 0 8 2
A normalizeSniffNameToClass() 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\Ruleset\Rule;
9
10
use Nette\Utils\Strings;
11
use Symplify\PHP7_CodeSniffer\Ruleset\Routing\Router;
12
use Symplify\PHP7_CodeSniffer\SniffFinder\SniffFinder;
13
use Symplify\PHP7_CodeSniffer\Standard\StandardFinder;
14
15
final class ReferenceNormalizer
16
{
17
    /**
18
     * @var SniffFinder
19
     */
20
    private $sniffFinder;
21
22
    /**
23
     * @var StandardFinder
24
     */
25
    private $standardFinder;
26
    
27
    /**
28
     * @var Router
29
     */
30
    private $router;
31
32 2
    public function __construct(SniffFinder $sniffFinder, StandardFinder $standardFinder, Router $router)
33
    {
34 2
        $this->sniffFinder = $sniffFinder;
35 2
        $this->standardFinder = $standardFinder;
36 2
        $this->router = $router;
37 2
    }
38
39 1
    public function normalize(string $reference) : array
40
    {
41 1
        if ($this->isSniffFileReference($reference)) {
42
            return [$reference];
43
        }
44
45
        return [
46 1
            $reference => $this->normalizeSniffNameToClass($reference)
47
        ];
48
    }
49
50 1
    public function isRulesetReference(string $reference) : bool
51
    {
52 1
        if (Strings::endsWith($reference, 'ruleset.xml')) {
53
            return true;
54
        }
55
56 1
        return false;
57
    }
58
59 2
    public function isStandardReference(string $reference) : bool
60
    {
61 2
        $standards = $this->standardFinder->getStandards();
62 2
        if (isset($standards[$reference])) {
63 2
            return true;
64
        }
65
66 2
        return false;
67
    }
68
69 1
    private function isSniffFileReference(string $reference) : bool
70
    {
71 1
        if (Strings::endsWith($reference, 'Sniff.php')) {
72
            return true;
73
        }
74
75 1
        return false;
76
    }
77
78 1
    private function normalizeSniffNameToClass(string $name) : string
79
    {
80 1
        return $this->router->getClassFromSniffName($name);
81
    }
82
}
83