Passed
Push — master ( 04bb0b...31510a )
by Daniel
11:10
created

ResponseBuilder::buildErrorResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 9
ccs 4
cts 4
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
        return [
20
            'error' => [
21 1
                'message' => $e->getMessage(),
22 1
                'code' => $e->getCode(),
23 1
                'id' => $uuid->toString()
24
            ]
25
        ];
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
        return [
36 1
            'data' => $data
37
        ];
38
    }
39
}
40