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

ReferenceNormalizer::isStandardReference()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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