Passed
Push — 6.x ( 9e1e65 )
by Phil
28:52 queued 04:40
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
    public function getHost(): ?string
32 57
    {
33
        return $this->host;
34 57
    }
35
36
    public function getName(): ?string
37 57
    {
38
        return $this->name;
39 57
    }
40
41
    public function getPort(): ?int
42 54
    {
43
        return $this->port;
44 54
    }
45
46
    public function getScheme(): ?string
47 60
    {
48
        return $this->scheme;
49 60
    }
50
51
    public function setHost(string $host): RouteConditionHandlerInterface
52 15
    {
53
        $this->host = $host;
54 15
        return $this->checkAndReturnSelf();
55 15
    }
56
57
    public function setName(string $name): RouteConditionHandlerInterface
58 9
    {
59
        $this->name = $name;
60 9
        return $this->checkAndReturnSelf();
61 9
    }
62
63
    public function setPort(int $port): RouteConditionHandlerInterface
64 9
    {
65
        $this->port = $port;
66 9
        return $this->checkAndReturnSelf();
67 9
    }
68
69
    public function setScheme(string $scheme): RouteConditionHandlerInterface
70 9
    {
71
        $this->scheme = $scheme;
72 9
        return $this->checkAndReturnSelf();
73 9
    }
74
75
    private function checkAndReturnSelf(): RouteConditionHandlerInterface
76 27
    {
77
        if ($this instanceof RouteConditionHandlerInterface) {
78 27
            return $this;
79 24
        }
80
81
        throw new RuntimeException(sprintf(
82 3
            'Trait (%s) must be consumed by an instance of (%s)',
83 3
            __TRAIT__,
84 3
            RouteConditionHandlerInterface::class
85 3
        ));
86
    }
87
}
88