CampaignMonitorResponse::getResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace MailMarketing\Entities;
4
5
use Illuminate\Support\Arr;
6
7
class CampaignMonitorResponse implements ResponseInterface
8
{
9
10
    protected \CS_REST_Wrapper_Result $response;
11
12 1
    public function __construct(\CS_REST_Wrapper_Result $response)
13
    {
14 1
        $this->response = $response;
15
    }
16
17 1
    public static function init($data): static
18
    {
19 1
        return new static($data);
20
    }
21
22
    public function getResponse(): \CS_REST_Wrapper_Result
23
    {
24
        return $this->response;
25
    }
26
27 1
    public function isSuccess(): bool
28
    {
29 1
        return $this->response->was_successful();
30
    }
31
32 1
    public function getErrorMessage(): string
33
    {
34 1
        $response = $this->get('Message');
35
36 1
        return is_string($response) ? $response : '';
37
    }
38
39 1
    public function get(?string $key = null, mixed $default = null): mixed
40
    {
41 1
        $formattedResponse = json_decode(json_encode($this->response->response), true);
42 1
        if (!is_null($key)) {
43 1
            return Arr::get($formattedResponse, $key, $default);
44
        }
45
46
        return $formattedResponse;
47
    }
48
}
49