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

SniffCodeToSniffsFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
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 37
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isMatch() 0 9 3
A create() 0 5 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