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

SniffCodeToSniffsFactory::isMatch()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

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 3
eloc 5
nc 2
nop 1
crap 3
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\Contract\Sniff\Factory\SniffFactoryInterface;
12
use Symplify\PHP7_CodeSniffer\Sniff\Routing\Router;
13
14
final class SniffCodeToSniffsFactory implements SniffFactoryInterface
15
{
16
    /**
17
     * @var Router
18
     */
19
    private $router;
20
21
    /**
22
     * @var SingleSniffFactory
23
     */
24
    private $singleSniffFactory;
25
26 12
    public function __construct(Router $router, SingleSniffFactory $singleSniffFactory)
27
    {
28 12
        $this->router = $router;
29 12
        $this->singleSniffFactory = $singleSniffFactory;
30 12
    }
31
32 7
    public function isMatch(string $reference) : bool
33
    {
34 7
        $partsCount = count(explode('.', $reference));
35 7
        if ($partsCount >= 3 && $partsCount <=4) {
36 7
            return true;
37
        }
38
39 5
        return false;
40
    }
41
42
    /**
43
     * @return Sniff[]
44
     */
45 7
    public function create(string $sniffCode) : array
46
    {
47 7
        $sniffClassName = $this->router->getClassFromSniffCode($sniffCode);
48 7
        return [$this->singleSniffFactory->create($sniffClassName)];
49
    }
50
}
51