ErrorSerializer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 15 2
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