Passed
Branch 5.x (508359)
by Phil
24:20
created

RouteConditionHandlerTrait::checkAndReturnSelf()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 10
rs 10
ccs 0
cts 0
cp 0
cc 2
nc 2
nop 0
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 48
    protected $scheme;
30
31 48
    public function getHost(): ?string
32
    {
33
        return $this->host;
34 51
    }
35
36 51
    public function getName(): ?string
37
    {
38
        return $this->name;
39 45
    }
40
41 45
    public function getPort(): ?int
42
    {
43
        return $this->port;
44 51
    }
45
46 51
    public function getScheme(): ?string
47
    {
48
        return $this->scheme;
49 9
    }
50
51 9
    public function setHost(string $host): RouteConditionHandlerInterface
52 9
    {
53
        $this->host = $host;
54
        return $this->checkAndReturnSelf();
55 6
    }
56
57 6
    public function setName(string $name): RouteConditionHandlerInterface
58 6
    {
59
        $this->name = $name;
60
        return $this->checkAndReturnSelf();
61 9
    }
62
63 9
    public function setPort(int $port): RouteConditionHandlerInterface
64 9
    {
65
        $this->port = $port;
66
        return $this->checkAndReturnSelf();
67 9
    }
68
69 9
    public function setScheme(string $scheme): RouteConditionHandlerInterface
70 9
    {
71
        $this->scheme = $scheme;
72
        return $this->checkAndReturnSelf();
73
    }
74
75
    private function checkAndReturnSelf(): RouteConditionHandlerInterface
76
    {
77
        if ($this instanceof RouteConditionHandlerInterface) {
78
            return $this;
79
        }
80
81
        throw new RuntimeException(sprintf(
82
            'Trait (%s) must be consumed by an instance of (%s)',
83
            __TRAIT__,
84
            RouteConditionHandlerInterface::class
85
        ));
86
    }
87
}
88