Passed
Push — master ( e63f1d...295fd2 )
by Andrea Marco
03:11 queued 14s
created

JsonApiException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toResponse() 0 3 1
A __construct() 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 1
    public function toResponse($request): Response
35
    {
36 1
        return (new JsonApiError(...$this->errors))->response();
37
    }
38
}
39