Passed
Push — main ( 7b6ef0...e0657e )
by Daniel
14:01
created

JsonEnabledResponse::withJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\Lib\Message;
6
7
use GuzzleHttp\Psr7\Response;
8
use Psr\Http\Message\ResponseInterface;
9
10
final class JsonEnabledResponse extends Response implements JsonEnabledResponseInterface
11
{
12 1
    public function withJson(mixed $data): ResponseInterface
13
    {
14 1
        $this->getBody()->write(
15 1
            json_encode($data, JSON_THROW_ON_ERROR|JSON_PRETTY_PRINT)
16 1
        );
17
18 1
        return $this->withHeader(
19 1
            'Content-Type',
20 1
            'application/json'
21 1
        );
22
    }
23
}
24