Passed
Pull Request — master (#5)
by Dmitriy
02:49
created

ResponseAccessor::getHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Testing;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\StreamInterface;
9
10
final class ResponseAccessor implements ResponseInterface
11
{
12 15
    public function __construct(private ResponseInterface $response)
13
    {
14
    }
15
16 3
    public function getContent(): string
17
    {
18 3
        $stream = $this->response->getBody();
19 3
        $stream->rewind();
20 3
        return $stream->getContents();
21
    }
22
23 1
    public function getContentAsJson(
24
        int $flags = JSON_OBJECT_AS_ARRAY | JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE
25
    ): mixed {
26 1
        return json_decode($this->getContent(), flags: $flags);
27
    }
28
29 2
    public function getProtocolVersion(): string
30
    {
31 2
        return $this->response->getProtocolVersion();
32
    }
33
34 1
    public function withProtocolVersion($version): ResponseAccessor
35
    {
36 1
        $response = $this->response->withProtocolVersion($version);
37 1
        return new self($response);
38
    }
39
40 1
    public function getHeaders(): array
41
    {
42 1
        return $this->response->getHeaders();
43
    }
44
45 1
    public function hasHeader($name): bool
46
    {
47 1
        return $this->response->hasHeader($name);
48
    }
49
50 4
    public function getHeader($name): array
51
    {
52 4
        return $this->response->getHeader($name);
53
    }
54
55 1
    public function getHeaderLine($name): string
56
    {
57 1
        return $this->response->getHeaderLine($name);
58
    }
59
60 1
    public function withHeader($name, $value): ResponseAccessor
61
    {
62 1
        $response = $this->response->withHeader($name, $value);
63 1
        return new self($response);
64
    }
65
66 2
    public function withAddedHeader($name, $value): ResponseAccessor
67
    {
68 2
        $response = $this->response->withAddedHeader($name, $value);
69 2
        return new self($response);
70
    }
71
72 1
    public function withoutHeader($name): ResponseAccessor
73
    {
74 1
        $response = $this->response->withoutHeader($name);
75 1
        return new self($response);
76
    }
77
78 1
    public function getBody(): StreamInterface
79
    {
80 1
        return $this->response->getBody();
81
    }
82
83 1
    public function withBody(StreamInterface $body): ResponseAccessor
84
    {
85 1
        $response = $this->response->withBody($body);
86 1
        return new self($response);
87
    }
88
89 2
    public function getStatusCode(): int
90
    {
91 2
        return $this->response->getStatusCode();
92
    }
93
94 1
    public function withStatus($code, $reasonPhrase = ''): ResponseAccessor
95
    {
96 1
        $response = $this->response->withStatus($code, $reasonPhrase);
97 1
        return new self($response);
98
    }
99
100 1
    public function getReasonPhrase(): string
101
    {
102 1
        return $this->response->getReasonPhrase();
103
    }
104
105 6
    public function getResponse(): ResponseInterface
106
    {
107 6
        return $this->response;
108
    }
109
}
110