Passed
Push — main ( 69b1a6...b43944 )
by Daniel
02:36
created

StreamResponder::__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 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Usox\HyperSonic\FeatureSet\V1161\Responder;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\StreamInterface;
9
10
final class StreamResponder extends AbstractBinaryResponder
11
{
12
    /**
13
     * @param array{
14
     *  contentType: string,
15
     *  stream: StreamInterface,
16
     *  estimatedContentLength?: int
17
     * } $streamData
18
     */
19 2
    public function __construct(
20
        private readonly array $streamData,
21
    ) {
22
    }
23
24 1
    public function writeResponse(ResponseInterface $response): ResponseInterface
25
    {
26 1
        if (array_key_exists('estimatedContentLength', $this->streamData)) {
27 1
            $response = $response->withHeader(
28
                'Content-Length',
29 1
                (string) $this->streamData['estimatedContentLength'],
30
            );
31
        }
32
33
        return $response
34 1
            ->withBody($this->streamData['stream'])
35 1
            ->withHeader('Content-Transfer-Encoding', 'binary')
36 1
            ->withHeader('Cache-Control', 'no-cache')
37 1
            ->withHeader('Content-Type', $this->streamData['contentType']);
38
    }
39
}
40