Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| IcapResponse | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| withHeader | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Ndrstmr\Icap\DTO; |
| 6 | |
| 7 | /** |
| 8 | * Immutable DTO representing an ICAP response. |
| 9 | */ |
| 10 | final readonly class IcapResponse |
| 11 | { |
| 12 | /** @var array<string, string[]> */ |
| 13 | public array $headers; |
| 14 | |
| 15 | /** |
| 16 | * @param int $statusCode HTTP status code, e.g. 200, 204, 500 |
| 17 | * @param array<string, string[]> $headers Response headers |
| 18 | * @param string $body Response body content |
| 19 | */ |
| 20 | public function __construct( |
| 21 | public int $statusCode, |
| 22 | array $headers = [], |
| 23 | public string $body = '' |
| 24 | ) { |
| 25 | $this->headers = array_map(fn ($v) => (array) $v, $headers); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @param string|string[] $value |
| 30 | */ |
| 31 | public function withHeader(string $name, string|array $value): self |
| 32 | { |
| 33 | $headers = $this->headers; |
| 34 | $headers[$name] = (array) $value; |
| 35 | |
| 36 | return new self( |
| 37 | $this->statusCode, |
| 38 | $headers, |
| 39 | $this->body, |
| 40 | ); |
| 41 | } |
| 42 | } |