ResponseBuilder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildResponse() 0 4 1
A buildErrorResponse() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Usox\JsonSchemaApi\Response;
6
7
use Ramsey\Uuid\UuidInterface;
8
use Throwable;
9
10
final class ResponseBuilder implements ResponseBuilderInterface
11
{
12
    /**
13
     * @return array{error: array{message: string, code: int, id: string}}
14
     */
15 1
    public function buildErrorResponse(
16
        Throwable $e,
17
        UuidInterface $uuid,
18
    ): array {
19 1
        return [
20 1
            'error' => [
21 1
                'message' => $e->getMessage(),
22 1
                'code' => $e->getCode(),
23 1
                'id' => $uuid->toString(),
24 1
            ],
25 1
        ];
26
    }
27
28
    /**
29
     * @param array<mixed, mixed> $data
30
     *
31
     * @return array{data: array<mixed, mixed>}
32
     */
33 1
    public function buildResponse(array $data): array
34
    {
35 1
        return [
36 1
            'data' => $data,
37 1
        ];
38
    }
39
}
40