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

SniffCodeToSniffsFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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