Test Failed
Pull Request — master (#3)
by Бабичев
02:15
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
use Bavix\Router\Rules\PatternRule;
6
7
class Route implements \Serializable
8
{
9
10
    /**
11
     * @var PatternRule
12
     */
13
    protected $rule;
14
15
    /**
16
     * @return array
17
     */
18
    public function getDefaults(): array
19
    {
20
        return $this->rule->getDefaults();
21
    }
22
23
    /**
24
     * @return array
25
     */
26
    public function getAttributes(): array
27
    {
28
        return $this->attributes ?? $this->getDefaults();
0 ignored issues
show
Bug Best Practice introduced by
The property attributes does not exist on Bavix\Router\Route. Did you maybe forget to declare it?
Loading history...
29
    }
30
31
    /**
32
     * @param string $method
33
     *
34
     * @return bool
35
     */
36
    protected function methodAllowed(string $method): bool
37
    {
38
        $methods = $this->rule->getMethods();
39
        return $methods === null || \in_array($method, $methods, true);
40
    }
41
42
    /**
43
     * @param string $uri
44
     *
45
     * @return Match
46
     */
47
    protected function match(string $uri): Match
48
    {
49
        return new Match($this->rule, $uri);
50
    }
51
52
    /**
53
     * @param string $uri
54
     * @param string $method
55
     *
56
     * @return bool
57
     */
58
    public function test(string $uri, string $method): bool
59
    {
60
        return $this->methodAllowed($method) && $this->match($uri)->isTest();
61
    }
62
63
    /**
64
     * @inheritdoc
65
     */
66 4
    public function serialize(): string
67
    {
68 4
69
    }
70 4
71
    /**
72
     * @inheritdoc
73
     */
74
    public function unserialize($serialized): void
75 4
    {
76 4
77
    }
78
79
}
80