Passed
Push — master ( 42b16f...37358f )
by Zlatin
01:56
created

ServerRequest   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 182
Duplicated Lines 0 %

Test Coverage

Coverage 9.09%

Importance

Changes 0
Metric Value
dl 0
loc 182
ccs 4
cts 44
cp 0.0909
rs 10
c 0
b 0
f 0
wmc 16

14 Methods

Rating   Name   Duplication   Size   Complexity  
A withAttribute() 0 6 1
A getAttribute() 0 6 2
A getParsedBody() 0 3 1
A getQueryParams() 0 3 1
A __construct() 0 3 1
A getAttributes() 0 3 1
A withoutAttribute() 0 10 2
A getServerParams() 0 3 1
A getUploadedFiles() 0 3 1
A withQueryParams() 0 6 1
A withUploadedFiles() 0 6 1
A withCookieParams() 0 6 1
A withParsedBody() 0 6 1
A getCookieParams() 0 3 1
1
<?php
2
namespace DevOp\Core\Http;
3
4
use DevOp\Core\Http\ServerRequest;
5
use Psr\Http\Message\UriInterface;
6
use Psr\Http\Message\StreamInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
9
class ServerRequest implements ServerRequestInterface
10
{
11
12
    use Traits\MessageTrait;
13
    use Traits\RequestTrait;
14
15
    /**
16
     * @var array
17
     */
18
    private $attributes = [];
19
20
    /**
21
     * @var array
22
     */
23
    private $cookieParams = [];
24
25
    /**
26
     * @var array
27
     */
28
    private $parsedBody = [];
29
30
    /**
31
     * @var array
32
     */
33
    private $queryParams = [];
34
35
    /**
36
     * @var array
37
     */
38
    private $serverParams = [];
39
40
    /**
41
     * @var array
42
     */
43
    private $uploadedFiles = [];
44
45
    /**
46
     * @param string $method
47
     * @param UriInterface $uri
48
     * @param array $headers
49
     * @param StreamInterface $body
50
     * @param string $version
51
     */
52 2
    public function __construct($method, UriInterface $uri, array $headers = [], StreamInterface $body, $version = '1.1')
53
    {
54 2
        return new Request($method, $uri, $headers, $body, $version);
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function getAttribute($name, $default = null)
61
    {
62
        if (array_key_exists($name, $this->attributes)) {
63
            return $this->attributes[$name];
64
        }
65
        return $default;
66
    }
67
68
    /**
69
     * @return array
70
     */
71 2
    public function getAttributes()
72
    {
73 2
        return $this->attributes;
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    public function getCookieParams()
80
    {
81
        return $this->cookieParams;
82
    }
83
84
    /**
85
     * @return mixed
86
     */
87
    public function getParsedBody()
88
    {
89
        return $this->parsedBody;
90
    }
91
92
    /**
93
     * @return array
94
     */
95
    public function getQueryParams()
96
    {
97
        return $this->queryParams;
98
    }
99
100
    /**
101
     * @return array
102
     */
103
    public function getServerParams()
104
    {
105
        return $this->serverParams;
106
    }
107
108
    /**
109
     * @return array
110
     */
111
    public function getUploadedFiles()
112
    {
113
        return $this->uploadedFiles;
114
    }
115
116
    /**
117
     * @param string $name
118
     * @param string $value
119
     * @return \DevOp\Core\Http\ServerRequest
120
     */
121
    public function withAttribute($name, $value)
122
    {
123
        $clone = clone $this;
124
        $clone->attributes[$name] = $value;
125
126
        return $clone;
127
    }
128
129
    /**
130
     * @param array $cookies
131
     * @return \DevOp\Core\Http\ServerRequest
132
     */
133
    public function withCookieParams(array $cookies)
134
    {
135
        $clone = clone $this;
136
        $clone->cookieParams = $cookies;
137
138
        return $clone;
139
    }
140
141
    /**
142
     * @param mixed $data
143
     * @return \DevOp\Core\Http\ServerRequest
144
     */
145
    public function withParsedBody($data)
146
    {
147
        $clone = clone $this;
148
        $clone->parsedBody = $data;
149
150
        return $clone;
151
    }
152
153
    /**
154
     * @param array $query
155
     * @return \DevOp\Core\Http\ServerRequest
156
     */
157
    public function withQueryParams(array $query)
158
    {
159
        $clone = clone $this;
160
        $clone->queryParams = $query;
161
162
        return $clone;
163
    }
164
165
    /**
166
     * @param array $uploadedFiles
167
     * @return \DevOp\Core\Http\ServerRequest
168
     */
169
    public function withUploadedFiles(array $uploadedFiles)
170
    {
171
        $clone = clone $this;
172
        $clone->uploadedFiles = $uploadedFiles;
173
174
        return $clone;
175
    }
176
177
    /**
178
     * @param string $name
179
     * @return \DevOp\Core\Http\ServerRequest|$this
180
     */
181
    public function withoutAttribute($name)
182
    {
183
        if (!array_key_exists($name, $this->attributes)) {
184
            return $this;
185
        }
186
187
        $clone = clone $this;
188
        unset($clone->attributes[$name]);
189
190
        return $clone;
191
    }
192
}
193