Passed
Pull Request — master (#73)
by Dmitriy
17:47 queued 02:50
created

HtmlResponseFormatter   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 7
c 1
b 0
f 0
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Yiisoft\Serializer\JsonSerializer;
9
10
final class HtmlResponseFormatter implements ResponseFormatterInterface
11
{
12
    /**
13
     * @var string the Content-Type header for the response
14
     */
15
    private string $contentType = 'text/html';
16
17
    /**
18
     * @var string the XML encoding. If not set, it will use the value of [[Response::charset]].
19
     */
20
    private string $encoding = 'UTF-8';
21
22
    public function format(DeferredResponse $response): ResponseInterface
23
    {
24
        $data = $response->getData();
25
        $response = $response->getResponse();
26
        $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

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