Passed
Push — master ( 184b95...3a4432 )
by 世昌
01:52
created

RouteMatcher::getAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula\route;
3
4
use Serializable;
5
use nebula\route\uri\UriMatcher;
6
7
/**
8
 * 路由匹配器
9
 *
10
 */
11
class RouteMatcher
12
{
13
    
14
    /**
15
     * 匹配的方法
16
     *
17
     * @var array
18
     */
19
    protected $methods;
20
21
    /**
22
     * 匹配的URI
23
     *
24
     * @var string
25
     */
26
    protected $uri;
27
28
    /**
29
     * 属性
30
     *
31
     * @var array
32
     */
33
    protected $attribute;
34
35
    /**
36
     * Uri匹配器
37
     *
38
     * @var UriMatcher
39
     */
40
    protected $matcher;
41
    
42
43
    public function __construct(array $methods, string $uri, array $attribute=[])
44
    {
45
        array_walk($methods, function ($value) {
46
            return strtoupper($value);
47
        });
48
        $this->methods = $methods;
49
        $this->uri = $uri;
50
        $this->matcher = UriMatcher::build($uri);
51
        $this->attribute = $attribute;
52
    }
53
    
54
    /**
55
     * Get 属性
56
     *
57
     * @return  array
58
     */
59
    public function getAttribute()
60
    {
61
        return $this->attribute;
62
    }
63
64
    /**
65
     * Set 属性
66
     *
67
     * @param  array  $attribute  属性
68
     *
69
     * @return  self
70
     */
71
    public function setAttribute(array $attribute)
72
    {
73
        $this->attribute = $attribute;
74
75
        return $this;
76
    }
77
78
    /**
79
     * Get 匹配的方法
80
     *
81
     * @return  string
82
     */
83
    public function getMethods()
84
    {
85
        return $this->methods;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->methods returns the type array which is incompatible with the documented return type string.
Loading history...
86
    }
87
88
    /**
89
     * Set 匹配的方法
90
     *
91
     * @param  string  $methods  匹配的方法
92
     *
93
     * @return  self
94
     */
95
    public function setMethods(string $methods)
96
    {
97
        $this->methods = $methods;
0 ignored issues
show
Documentation Bug introduced by
It seems like $methods of type string is incompatible with the declared type array of property $methods.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
98
99
        return $this;
100
    }
101
102
    /**
103
     * Get 匹配的URI
104
     *
105
     * @return  string
106
     */
107
    public function getUri()
108
    {
109
        return $this->uri;
110
    }
111
112
    /**
113
     * Set 匹配的URI
114
     *
115
     * @param  string  $uri  匹配的URI
116
     *
117
     * @return  self
118
     */
119
    public function setUri(string $uri)
120
    {
121
        $this->uri = $uri;
122
123
        return $this;
124
    }
125
126
    /**
127
     * Get uri匹配器
128
     *
129
     * @return  UriMatcher
130
     */
131
    public function getMatcher()
132
    {
133
        return $this->matcher;
134
    }
135
}
136