Passed
Pull Request — master (#75)
by
unknown
22:37 queued 07:36
created

JSONConverter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 4
c 1
b 0
f 0
dl 0
loc 14
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A convert() 0 4 1
A setHeaders() 0 3 1
A getFormat() 0 3 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