Passed
Pull Request — master (#3)
by Бабичев
01:25
created

Route::methodValid()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 3
nc 5
nop 1
dl 0
loc 5
rs 9.2
c 0
b 0
f 0
ccs 4
cts 4
cp 1
crap 4
1
<?php
2
3
namespace Bavix\Router;
4
5
class Route implements Routable
6
{
7
8
    /**
9
     * @var Match
10
     */
11
    protected $match;
12
13
    /**
14
     * @param Match $match
15
     */
16 2
    public function __construct(Match $match)
17
    {
18 2
        $this->match = $match;
19 2
    }
20
21
    public function getMethod(): string
22
    {
23
        return $this->match->getMethod();
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    public function getProtocol(): string
30
    {
31
        return $this->match->getProtocol();
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function getHost(): string
38
    {
39
        return $this->match->getHost();
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function getName(): string
46
    {
47
        return $this->match->getRule()->getName();
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getPathValue(): string
54
    {
55
        return $this->match->getRule()->getPath()->getValue();
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getPath(): string
62
    {
63
        return $this->match->getPath();
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getPathPattern(): string
70
    {
71
        return $this->match->getRule()->getPath()->getPattern();
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getPattern(): string
78
    {
79
        return $this->match->getPattern();
80
    }
81
82
    /**
83
     * @return array
84
     */
85 2
    public function getAttributes(): array
86
    {
87 2
        return $this->match->getAttributes();
88
    }
89
90
    /**
91
     * @return array
92
     */
93
    public function getExtends(): array
94
    {
95
        return $this->match->getRule()->getExtends();
96
    }
97
98
    /**
99
     * @return array
100
     */
101
    public function getDefaults(): array
102
    {
103
        return $this->match->getRule()->getDefaults();
104
    }
105
106
    /**
107
     * @return array
108
     */
109
    public function getGroups(): array
110
    {
111
        return $this->match->getGroups();
112
    }
113
114
    /**
115
     * @return null|array
116
     */
117
    public function getMethods(): ?array
118
    {
119
        return $this->match->getRule()->getMethods();
120
    }
121
122
    /**
123
     * @return array
124
     */
125
    public function __sleep(): array
126
    {
127
        return ['match'];
128
    }
129
130
    /**
131
     * @inheritdoc
132
     */
133
    public function serialize(): string
134
    {
135
        return \serialize($this->match);
136
    }
137
138
    /**
139
     * @inheritdoc
140
     */
141
    public function unserialize($serialized): void
142
    {
143
        $this->match = \unserialize($serialized, (array)null);
144
    }
145
146
    /**
147
     * @inheritdoc
148
     */
149
    public function jsonSerialize(): array
150
    {
151
        return [
152
            'protocol' => $this->getProtocol(),
153
            'host' => $this->getHost(),
154
            'name' => $this->getName(),
155
            'path' => $this->getPath(),
156
            'pathValue' => $this->getPathValue(),
157
            'pathPattern' => $this->getPathPattern(),
158
            'pattern' => $this->getPattern(),
159
            'extends' => $this->getExtends(),
160
            'attributes' => $this->getAttributes(),
161
            'defaults' => $this->getDefaults(),
162
            'methods' => $this->getMethods(),
163
        ];
164
    }
165
166
}
167