ResponseBuilder::buildResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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