SniffCodeToSniffsFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 43
ccs 15
cts 15
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 11 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\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 13
    public function __construct(Router $router, SingleSniffFactory $singleSniffFactory)
27
    {
28 13
        $this->router = $router;
29 13
        $this->singleSniffFactory = $singleSniffFactory;
30 13
    }
31
32 9
    public function isMatch(string $reference) : bool
33
    {
34 9
        $partsCount = count(explode('.', $reference));
35 9
        if ($partsCount >= 3 && $partsCount <=4) {
36 9
            return true;
37
        }
38
39 7
        return false;
40
    }
41
42
    /**
43
     * @return Sniff[]
44
     */
45 9
    public function create(string $sniffCode) : array
46
    {
47 9
        $sniffClassName = $this->router->getClassFromSniffCode($sniffCode);
48 9
        $sniff = $this->singleSniffFactory->create($sniffClassName);
49 9
        if ($sniff !== null) {
50 9
            return [$sniff];
51
        }
52
53
54 1
        return [];
55
    }
56
}
57