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

JsonEnabledResponse   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 6
c 1
b 0
f 0
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A withJson() 0 9 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