RespondWithJsonErrorJob::handle()   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 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Anfischer\Foundation\Domains\Http\Jobs;
4
5
use Anfischer\Foundation\Job\Job;
6
use Illuminate\Contracts\Routing\ResponseFactory;
7
use Illuminate\Http\JsonResponse;
8
9
class RespondWithJsonErrorJob extends Job
10
{
11
    protected $content;
12
    protected $status;
13
    protected $headers;
14
    protected $options;
15
16 4
    public function __construct(
17
        string $message = 'An error occurred',
18
        int $code = 400,
19
        int $status = 400,
20
        array $headers = [],
21
        int $options = 0
22
    ) {
23 4
        $this->content = [
24 4
            'status' => $status,
25
            'error' => [
26 4
                'code' => $code,
27 4
                'message' => $message,
28
            ],
29
        ];
30
31 4
        $this->status = $status;
32 4
        $this->headers = $headers;
33 4
        $this->options = $options;
34 4
    }
35
36 4
    public function handle(ResponseFactory $response) : JsonResponse
37
    {
38 4
        return $response->json($this->content, $this->status, $this->headers, $this->options);
39
    }
40
}
41