Passed
Push — 5.x ( b66c10...1ca894 )
by Phil
01:52 queued 11s
created

RouteConditionHandlerTrait::isExtraConditionMatch()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.2222
cc 6
nc 4
nop 2
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\Route;
6
7
use RuntimeException;
8
9
trait RouteConditionHandlerTrait
10
{
11
    /**
12
     * @var ?string
13
     */
14
    protected $host;
15
16
    /**
17
     * @var ?string
18
     */
19
    protected $name;
20
21
    /**
22
     * @var ?int
23
     */
24
    protected $port;
25
26
    /**
27
     * @var ?string
28
     */
29
    protected $scheme;
30
31 51
    public function getHost(): ?string
32
    {
33 51
        return $this->host;
34
    }
35
36 54
    public function getName(): ?string
37
    {
38 54
        return $this->name;
39
    }
40
41 48
    public function getPort(): ?int
42
    {
43 48
        return $this->port;
44
    }
45
46 54
    public function getScheme(): ?string
47
    {
48 54
        return $this->scheme;
49
    }
50
51 12
    public function setHost(string $host): RouteConditionHandlerInterface
52
    {
53 12
        $this->host = $host;
54 12
        return $this->checkAndReturnSelf();
55
    }
56
57 9
    public function setName(string $name): RouteConditionHandlerInterface
58
    {
59 9
        $this->name = $name;
60 9
        return $this->checkAndReturnSelf();
61
    }
62
63 9
    public function setPort(int $port): RouteConditionHandlerInterface
64
    {
65 9
        $this->port = $port;
66 9
        return $this->checkAndReturnSelf();
67
    }
68
69 9
    public function setScheme(string $scheme): RouteConditionHandlerInterface
70
    {
71 9
        $this->scheme = $scheme;
72 9
        return $this->checkAndReturnSelf();
73
    }
74
75 24
    private function checkAndReturnSelf(): RouteConditionHandlerInterface
76
    {
77 24
        if ($this instanceof RouteConditionHandlerInterface) {
78 21
            return $this;
79
        }
80
81 3
        throw new RuntimeException(sprintf(
82 3
            'Trait (%s) must be consumed by an instance of (%s)',
83 3
            __TRAIT__,
84 3
            RouteConditionHandlerInterface::class
85
        ));
86
    }
87
}
88