JsonApiException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cerbero\JsonApiError\Exceptions;
6
7
use Cerbero\JsonApiError\Data\JsonApiErrorData;
8
use Cerbero\JsonApiError\JsonApiError;
9
use Exception;
10
use Illuminate\Contracts\Support\Responsable;
11
use Symfony\Component\HttpFoundation\Response;
12
13
/**
14
 * The exception thrown to render the JSON:API errors.
15
 */
16
class JsonApiException extends Exception implements Responsable
17
{
18
    /**
19
     * @var JsonApiErrorData[] $errors
20
     */
21
    public readonly array $errors;
22
23
    /**
24
     * Instantiate the class.
25
     */
26 1
    public function __construct(JsonApiErrorData ...$errors)
27
    {
28 1
        $this->errors = $errors;
0 ignored issues
show
Bug introduced by
The property errors is declared read-only in Cerbero\JsonApiError\Exceptions\JsonApiException.
Loading history...
29
    }
30
31
    /**
32
     * Render the JSON:API errors.
33
     *
34
     * @param \Illuminate\Http\Request $request
35
     */
36 1
    public function toResponse($request): Response
37
    {
38 1
        return (new JsonApiError(...$this->errors))->toResponse($request);
39
    }
40
}
41