Passed
Pull Request — master (#75)
by
unknown
10:25
created

JSONConverter::setHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Stream\Data;
6
7
use Psr\Http\Message\MessageInterface;
8
9
final class JSONConverter implements Converter
10
{
11
    public static function getFormat(): string
12
    {
13
        return 'application/json';
14
    }
15
    public function setHeaders(MessageInterface $message): MessageInterface
16
    {
17
        return $message->withHeader('Content-Type', static::getFormat());
18
    }
19
    public function convert($data, array $params = []) : string
20
    {
21
        // of course you can use JsonSerializer
22
        return json_encode($data, JSON_PRETTY_PRINT|JSON_INVALID_UTF8_IGNORE|JSON_UNESCAPED_UNICODE);
23
    }
24
}
25