ErrorResponse   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

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