ErrorResponse::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 12
rs 10
1
<?php
2
3
/**
4
 * This file is part of the bugloos/error-response-bundle project.
5
 * (c) Bugloos <https://bugloos.com/>
6
 * For the full copyright and license information, please view
7
 * the LICENSE file that was distributed with this source code.
8
 */
9
10
namespace Bugloos\ErrorResponseBundle\Response;
11
12
use Symfony\Component\HttpFoundation\JsonResponse;
13
14
/**
15
 * @author Mojtaba Gheytasi <[email protected]>
16
 */
17
class ErrorResponse extends JsonResponse
18
{
19
    public function __construct(
20
        int $status,
21
        string $message,
22
        array $errors = [],
23
        array $headers = ['Content-Type' => 'application/json'],
24
        bool $json = false
25
    ) {
26
        parent::__construct(
27
            $this->format($status, $message, $errors),
28
            $status,
29
            $headers,
30
            $json
31
        );
32
    }
33
34
    private function format(int $statusCode, string $message, array $errors = []): array
35
    {
36
        return [
37
            'statusCode' => $statusCode,
38
            'message' => $message,
39
            'errors' => $errors,
40
        ];
41
    }
42
}
43