Passed
Pull Request — master (#2)
by Byron
02:37
created

ValidationException::render()   A

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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Webtools\JsonSchemaRequest\Exceptions;
4
5
use Illuminate\Http\Response;
6
use Webtools\JsonSchemaRequest\JsonSchemaValidator;
7
8
class ValidationException extends \Exception
9
{
10
    public JsonSchemaValidator $validator;
11
12
    public int $status = Response::HTTP_UNPROCESSABLE_ENTITY;
13
14 4
    public function __construct(JsonSchemaValidator $validator)
15
    {
16 4
        parent::__construct('The given data was invalid.');
17 4
        $this->validator = $validator;
18 4
    }
19
20 1
    public function report()
21
    {
22
        // Do not report this exception.
23 1
    }
24
25 1
    public function render()
26
    {
27 1
        return response()->json(['errors' => $this->validator->errors()], $this->status);
28
    }
29
}