ErrorResponse::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 14
ccs 9
cts 9
cp 1
crap 3
rs 10
1
<?php
2
3
namespace Igorsgm\Ghost\Responses;
4
5
use Illuminate\Http\Client\Response;
6
use Illuminate\Support\Collection;
7
8
class ErrorResponse
9
{
10
    private Response $response;
11
12
    /**
13
     * @var bool
14
     */
15
    public $success = false;
16
17
    /**
18
     * @var Collection|array
19
     */
20
    public $errors = [];
21
22 4
    public function __construct(Response $response)
23
    {
24 4
        $this->response = $response;
25 4
        $this->handle();
26
    }
27
28
    /**
29
     * @return bool
30
     */
31 4
    private function handle()
32
    {
33 4
        $this->errors = collect();
34
35 4
        if (! config('ghost.debug.enabled')) {
36 1
            return $this->errors->push((object) [
37 1
                'message' => config('ghost.debug.default_error_message'),
38 1
            ]);
39
        }
40
41 3
        $responseErrors = data_get($this->response->json(), 'errors', []);
42
43 3
        foreach ($responseErrors as $error) {
44 3
            $this->errors->push((object) $error);
45
        }
46
    }
47
}
48