CampaignMonitorResponse   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 81.25%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 40
ccs 13
cts 16
cp 0.8125
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 3 1
A getErrorMessage() 0 5 2
A __construct() 0 3 1
A get() 0 8 2
A getResponse() 0 3 1
A isSuccess() 0 3 1
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