StreamResponder::writeResponse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 14
ccs 11
cts 11
cp 1
crap 2
rs 9.9666
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 2
    }
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 1
                'Content-Length',
29 1
                (string) $this->streamData['estimatedContentLength'],
30 1
            );
31
        }
32
33 1
        return $response
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response->withBo...eamData['contentType']) returns the type Psr\Http\Message\MessageInterface which includes types incompatible with the type-hinted return Psr\Http\Message\ResponseInterface.
Loading history...
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