RespondWithJsonErrorJob   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 30
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

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