ErrorSerializer::format()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 3
dl 0
loc 15
ccs 6
cts 6
cp 1
crap 2
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
namespace Flugg\Responder\Serializers;
4
5
use Flugg\Responder\Contracts\ErrorSerializer as ErrorSerializerContract;
6
7
/**
8
 * A serializer class responsible for formatting error data.
9
 *
10
 * @package flugger/laravel-responder
11
 * @author  Alexander Tømmerås <[email protected]>
12
 * @license The MIT License
13
 */
14
class ErrorSerializer implements ErrorSerializerContract
15
{
16
    /**
17
     * Format the error data.
18
     *
19
     * @param  mixed|null  $errorCode
20
     * @param  string|null $message
21
     * @param  array|null  $data
22
     * @return array
23
     */
24 10
    public function format($errorCode = null, string $message = null, array $data = null): array
25
    {
26
        $response = [
27
            'error' => [
28 10
                'code' => $errorCode,
29 10
                'message' => $message,
30
            ],
31
        ];
32
33 10
        if (is_array($data)) {
34 1
            $response['error'] = array_merge($response['error'], $data);
35
        }
36
37 10
        return $response;
38
    }
39
}
40