Total Complexity | 9 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Coverage | 85.71% |
Changes | 0 |
1 | <?php |
||
8 | class ApiResponse |
||
9 | { |
||
10 | /** @var string */ |
||
11 | protected $url; |
||
12 | /** @var array */ |
||
13 | protected $options; |
||
14 | /** @var ResponseInterface */ |
||
15 | protected $response; |
||
16 | /** @var array */ |
||
17 | protected $body; |
||
18 | |||
19 | 9 | public function __construct(string $url, array $options, ResponseInterface $response) |
|
20 | { |
||
21 | 9 | $this->url = $url; |
|
22 | 9 | $this->options = $options; |
|
23 | 9 | $this->response = $response; |
|
24 | 9 | $this->body = json_decode((string) $response->getBody(), true); |
|
25 | 9 | } |
|
26 | |||
27 | 9 | public function getStatusCode(): int |
|
28 | { |
||
29 | 9 | return (int) $this->response->getStatusCode(); |
|
30 | } |
||
31 | |||
32 | 9 | public function isSuccess(): bool |
|
33 | { |
||
34 | 9 | return $this->getStatusCode() >= 200 && $this->getStatusCode() <= 299; |
|
35 | } |
||
36 | |||
37 | 4 | public function getHttpMessage(): string |
|
38 | { |
||
39 | 4 | return $this->response->getReasonPhrase() ?? ''; |
|
40 | } |
||
41 | |||
42 | 4 | public function getContents(): array |
|
45 | } |
||
46 | |||
47 | 1 | public function getErrors() |
|
48 | { |
||
49 | 1 | if ($this->isSuccess()) { |
|
63 |