ServerRequest::withParsedBody()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Aidphp\Http;
6
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Http\Message\StreamInterface;
9
10
class ServerRequest extends Request implements ServerRequestInterface
11
{
12
    private $serverParams;
13
    private $cookieParams;
14
    private $queryParams;
15
    private $uploadedFiles;
16
    private $parsedBody;
17
    private $attributes = [];
18
19 35
    public function __construct(
20
        string $method,
21
        $uri,
22
        array $headers = [],
23
        StreamInterface $body = null,
24
        string $version = '1.1',
25
        array $serverParams = [],
26
        array $queryParams  = [],
27
        $parsedBody = null,
28
        array $cookieParams  = [],
29
        array $uploadedFiles = []
30
    )
31
    {
32 35
        $this->serverParams  = $serverParams;
33 35
        $this->queryParams   = $queryParams;
34 35
        $this->parsedBody    = $parsedBody;
35 35
        $this->cookieParams  = $cookieParams;
36 35
        $this->uploadedFiles = $uploadedFiles;
37 35
        parent::__construct($method, $uri, $headers, $body, $version);
38 35
    }
39
40 13
    public function getServerParams(): array
41
    {
42 13
        return $this->serverParams;
43
    }
44
45 2
    public function getCookieParams(): array
46
    {
47 2
        return $this->cookieParams;
48
    }
49
50 1
    public function withCookieParams(array $cookies): self
51
    {
52 1
        $new = clone $this;
53 1
        $new->cookieParams = $cookies;
54 1
        return $new;
55
    }
56
57 2
    public function getQueryParams(): array
58
    {
59 2
        return $this->queryParams;
60
    }
61
62 1
    public function withQueryParams(array $query): self
63
    {
64 1
        $new = clone $this;
65 1
        $new->queryParams = $query;
66 1
        return $new;
67
    }
68
69 8
    public function getUploadedFiles(): array
70
    {
71 8
        return $this->uploadedFiles;
72
    }
73
74 1
    public function withUploadedFiles(array $uploadedFiles): self
75
    {
76 1
        $new = clone $this;
77 1
        $new->uploadedFiles = $uploadedFiles;
78 1
        return $new;
79
    }
80
81 2
    public function getParsedBody()
82
    {
83 2
        return $this->parsedBody;
84
    }
85
86 1
    public function withParsedBody($data): self
87
    {
88 1
        $new = clone $this;
89 1
        $new->parsedBody = $data;
90 1
        return $new;
91
    }
92
93 3
    public function getAttributes(): array
94
    {
95 3
        return $this->attributes;
96
    }
97
98 2
    public function getAttribute($attribute, $default = null)
99
    {
100 2
        return array_key_exists($attribute, $this->attributes) ? $this->attributes[$attribute] : $default;
101
    }
102
103 2
    public function withAttribute($attribute, $value): self
104
    {
105 2
        $new = clone $this;
106 2
        $new->attributes[$attribute] = $value;
107 2
        return $new;
108
    }
109
110 2
    public function withoutAttribute($attribute): self
111
    {
112 2
        $new = clone $this;
113 2
        unset($new->attributes[$attribute]);
114 2
        return $new;
115
    }
116
}