Passed
Pull Request — master (#73)
by Dmitriy
14:14
created

HtmlResponseFormatter::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App;
6
7
use Psr\Http\Message\ResponseInterface;
8
9
final class HtmlResponseFormatter implements ResponseFormatterInterface
10
{
11
    /**
12
     * @var string the Content-Type header for the response
13
     */
14
    private string $contentType = 'text/html';
15
16
    /**
17
     * @var string the XML encoding. If not set, it will use the value of [[Response::charset]].
18
     */
19
    private string $encoding = 'UTF-8';
20
21
    public function format(DeferredResponse $deferredResponse): ResponseInterface
22
    {
23
        $data = $deferredResponse->getData();
24
        $response = $deferredResponse->getResponse();
25
        $response->getBody()->write($data);
0 ignored issues
show
Bug introduced by
It seems like $data can also be of type object; however, parameter $string of Psr\Http\Message\StreamInterface::write() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
        $response->getBody()->write(/** @scrutinizer ignore-type */ $data);
Loading history...
26
27
        return $response->withHeader('Content-Type', $this->contentType . '; charset=' . $this->encoding);
28
    }
29
}
30