Passed
Pull Request — master (#53)
by Sergei
02:59
created

BadRequestResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
c 1
b 1
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
eloc 0
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Runner\Http;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\StreamInterface;
9
use RuntimeException;
10
use Yiisoft\Http\Status;
11
12
/**
13
 * @internal
14
 */
15
final class BadRequestResponse implements ResponseInterface
16
{
17 14
    public function __construct(
18
        private string $reasonPhrase,
19
    ) {
20 14
    }
21
22 2
    public function getProtocolVersion(): string
23
    {
24 2
        return '1.1';
25
    }
26
27 1
    public function withProtocolVersion(string $version): void
28
    {
29 1
        throw new RuntimeException('Method "withProtocolVersion" is not supported.');
30
    }
31
32 2
    public function getHeaders(): array
33
    {
34 2
        return [];
35
    }
36
37 1
    public function hasHeader(string $name): bool
38
    {
39 1
        return false;
40
    }
41
42 1
    public function getHeader(string $name): array
43
    {
44 1
        return [];
45
    }
46
47 1
    public function getHeaderLine(string $name): string
48
    {
49 1
        return '';
50
    }
51
52 1
    public function withHeader(string $name, $value): self
53
    {
54 1
        throw new RuntimeException('Method "withHeader" is not supported.');
55
    }
56
57 1
    public function withAddedHeader(string $name, $value): self
58
    {
59 1
        throw new RuntimeException('Method "withAddedHeader" is not supported.');
60
    }
61
62
    /**
63
     * @psalm-suppress MoreSpecificReturnType, LessSpecificReturnStatement It's bug in Psalm < 5
64
     */
65 2
    public function withoutHeader(string $name): self
66
    {
67 2
        return $this;
68
    }
69
70 9
    public function getBody(): StreamInterface
71
    {
72 9
        return new class () implements StreamInterface {
73
            public function __toString(): string
74
            {
75 1
                throw new RuntimeException('Method "__toString" is not supported.');
76
            }
77
78
            public function close(): void
79
            {
80 1
            }
81
82
            public function detach()
83
            {
84 1
                return null;
85
            }
86
87
            public function getSize(): ?int
88
            {
89 1
                return null;
90
            }
91
92
            public function tell(): int
93
            {
94 1
                throw new RuntimeException('Method "tell" is not supported.');
95
            }
96
97
            public function eof(): bool
98
            {
99 1
                return false;
100
            }
101
102
            public function isSeekable(): bool
103
            {
104 1
                return false;
105
            }
106
107
            public function seek(int $offset, int $whence = SEEK_SET): void
108
            {
109 1
                throw new RuntimeException('Method "seek" is not supported.');
110
            }
111
112
            public function rewind(): void
113
            {
114 1
                throw new RuntimeException('Method "rewind" is not supported.');
115
            }
116
117
            public function isWritable(): bool
118
            {
119 1
                return false;
120
            }
121
122
            public function write(string $string): void
123
            {
124 1
                throw new RuntimeException('Method "write" is not supported.');
125
            }
126
127
            public function isReadable(): bool
128
            {
129 2
                return false;
130
            }
131
132
            public function read(int $length): void
133
            {
134 1
                throw new RuntimeException('Method "read" is not supported.');
135
            }
136
137
            public function getContents(): void
138
            {
139 1
                throw new RuntimeException('Method "getContents" is not supported.');
140
            }
141
142
            public function getMetadata(?string $key = null): mixed
143
            {
144 1
                return null;
145
            }
146 9
        };
147
    }
148
149 1
    public function withBody(StreamInterface $body): self
150
    {
151 1
        throw new RuntimeException('Method "withBody" is not supported.');
152
    }
153
154 2
    public function getStatusCode(): int
155
    {
156 2
        return Status::BAD_REQUEST;
157
    }
158
159 1
    public function withStatus(int $code, string $reasonPhrase = ''): self
160
    {
161 1
        throw new RuntimeException('Method "withStatus" is not supported.');
162
    }
163
164 2
    public function getReasonPhrase(): string
165
    {
166 2
        return $this->reasonPhrase;
167
    }
168
}
169