Test Failed
Push — master ( 0b6467...e6142c )
by Alexpts
16:38
created

ServerRequest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 79
ccs 28
cts 28
cp 1
rs 10
wmc 13

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A withUploadedFiles() 0 4 1
A getUploadedFiles() 0 3 1
A getParsedBody() 0 3 1
A getQueryParams() 0 3 1
A withParsedBody() 0 8 4
A withQueryParams() 0 4 1
A getCookieParams() 0 3 1
A withCookieParams() 0 4 1
A getServerParams() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace PTS\Psr7;
5
6
use InvalidArgumentException;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Http\Message\UploadedFileInterface;
9
use Psr\Http\Message\UriInterface;
10
use PTS\Psr7\Response\ServerMessageInterface;
11
use function is_array;
12
use function is_object;
13
14
class ServerRequest extends Request implements ServerRequestInterface, ServerMessageInterface
15
{
16
    use ServerMessage;
17
18
    protected array $cookieParams = [];
19
20
    /** @var array|object|null */
21
    protected $parsedBody;
22
    protected array $queryParams = [];
23
    protected array $serverParams;
24
25
    /** @var UploadedFileInterface[] */
26
    protected array $uploadedFiles = [];
27
28
    public function __construct(
29 10
        string $method,
30
        UriInterface $uri,
31
        array $headers = [],
32
        $body = null,
33
        string $version = '1.1',
34
        array $serverParams = []
35
    ) {
36
        parent::__construct($method, $uri, $headers, $body, $version);
37 10
38
        $this->serverParams = $serverParams;
39 10
        parse_str($uri->getQuery(), $this->queryParams);
40 10
    }
41 10
42
    public function getServerParams(): array
43 1
    {
44
        return $this->serverParams;
45 1
    }
46
47
    public function getUploadedFiles(): array
48 1
    {
49
        return $this->uploadedFiles;
50 1
    }
51
52
    public function withUploadedFiles(array $uploadedFiles)
53 1
    {
54
        $this->uploadedFiles = $uploadedFiles;
55 1
        return $this;
56 1
    }
57
58
    public function getCookieParams(): array
59 1
    {
60
        return $this->cookieParams;
61 1
    }
62
63
    public function withCookieParams(array $cookies)
64 1
    {
65
        $this->cookieParams = $cookies;
66 1
        return $this;
67 1
    }
68
69
    public function getQueryParams(): array
70 2
    {
71
        return $this->queryParams;
72 2
    }
73
74
    public function withQueryParams(array $query)
75 1
    {
76
        $this->queryParams = $query;
77 1
        return $this;
78 1
    }
79
80
    public function getParsedBody()
81 1
    {
82
        return $this->parsedBody;
83 1
    }
84
85
    public function withParsedBody($data)
86 2
    {
87
        if (!is_array($data) && !is_object($data) && null !== $data) {
88 2
            throw new InvalidArgumentException('First parameter to withParsedBody MUST be object, array or null');
89 1
        }
90
91
        $this->parsedBody = $data;
92 1
        return $this;
93 1
    }
94
}
95