Passed
Push — master ( 2a29e8...d38419 )
by 世昌
01:50
created

Request::getQueryParameter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula\application;
3
4
use nebula\component\request\Request as BaseRequest;
5
use nebula\component\route\RequestInterface;
6
7
/**
8
 * 网页请求封装
9
 */
10
class Request extends BaseRequest implements RequestInterface
11
{
12
    protected $urlParameter;
13
14
    /**
15
     * 设置路由匹配值
16
     *
17
     * @param array $value
18
     * @return void
19
     */
20
    public function setUrlParameter(array $value) {
21
        $this->urlParameter = $value;
22
    }
23
24
    /**
25
     * 获取GET值
26
     *
27
     * @param string|null $name
28
     * @param mixed $default
29
     * @return void
30
     */
31
    public function getParameter(?string $name = null, $default = null) {
32
        if (is_null($name)) {
33
            return array_merge($this->queryParameter, $this->urlParameter);
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_merge($this...r, $this->urlParameter) returns the type array which is incompatible with the documented return type void.
Loading history...
34
        }
35
        return $this->urlParameter[$name] && $this->queryParameter[$name] ?? $default;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->urlParamet...eter[$name] ?? $default also could return the type boolean which is incompatible with the documented return type void.
Loading history...
36
    }
37
38
    /**
39
     * 获取查询参数
40
     *
41
     * @param string|null $name
42
     * @param mixed $default
43
     * @return void
44
     */
45
    public function getQueryParameter(?string $name = null, $default = null) {
46
        if (is_null($name)) {
47
            return $this->queryParameter;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->queryParameter returns the type array which is incompatible with the documented return type void.
Loading history...
48
        }
49
        return $this->queryParameter[$name] ?? $default;
50
    }
51
52
    /**
53
     * 获取URL中的参数
54
     *
55
     * @param string|null $name
56
     * @param mixed $default
57
     * @return void
58
     */
59
    public function getUrlParameter(?string $name = null, $default = null) {
60
        if (is_null($name)) {
61
            return $this->urlParameter;
62
        }
63
        return $this->urlParameter[$name] ?? $default;
64
    }
65
}
66