JsonApiException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 23
ccs 4
cts 4
cp 1
rs 10
c 2
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A toResponse() 0 3 1
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