SniffCodeToSniffsFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
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\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