Passed
Pull Request — master (#73)
by Dmitriy
12:32
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.
18
     */
19
    private string $encoding = 'UTF-8';
20
21
    public function format(Response $deferredResponse): ResponseInterface
22
    {
23
        $data = $deferredResponse->getData();
24
        $response = $deferredResponse->getResponse();
25
        $response->getBody()->write((string)$data);
26
27
        return $response->withHeader('Content-Type', $this->contentType . '; charset=' . $this->encoding);
28
    }
29
30
    public function setEncoding(string $encoding): void
31
    {
32
        $this->encoding = $encoding;
33
    }
34
}
35