Completed
Push — master ( 96682a...0cd473 )
by Dominik
01:14
created

HetrixtoolsServiceResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 67
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromJson() 0 20 4
1
<?php
2
3
4
namespace Azine\MailgunWebhooksBundle\Services\HetrixtoolsService;
5
6
7
class HetrixtoolsServiceResponse
8
{
9
    const RESPONSE_STATUS_SUCCESS = 'SUCCESS';
10
    const RESPONSE_STATUS_ERROR = 'ERROR';
11
    const BLACKLIST_CHECK_IN_PROGRESS = 'blacklist check in progress for this ipv4';
12
13
    /**
14
     * @var string
15
     */
16
    public $status;
17
18
    /**
19
     * @var int
20
     */
21
    public $api_calls_left;
22
23
    /**
24
     * @var int
25
     */
26
    public $blacklist_check_credits_left;
27
28
    /**
29
     * @var int
30
     */
31
    public $blacklisted_count;
32
33
    /**
34
     * @var array
35
     */
36
    public $blacklisted_on;
37
38
    /**
39
     * @var array
40
     */
41
    public $links;
42
43
    /**
44
     * @var string
45
     */
46
    public $error_message;
47
48
    /**
49
     * @param string $response
50
     * @throws \InvalidArgumentException
51
     * @return HetrixtoolsServiceResponse $responseObject
52
     */
53 5
    public static function fromJson($response)
54
    {
55 5
        $response = json_decode($response, true);
56
57 5
        if(!is_array($response)) {
58 3
            throw new \InvalidArgumentException('Invalid JSON provided');
59
        }
60
61 2
        $responseObject = new self();
62
63 2
        foreach($responseObject as $key => $value){
0 ignored issues
show
Bug introduced by
The expression $responseObject of type object<Azine\MailgunWebh...ixtoolsServiceResponse> is not traversable.
Loading history...
64
65 2
            if(isset($response[$key])){
66
67 2
                $responseObject->$key = $response[$key];
68 2
            }
69 2
        }
70
71 2
        return $responseObject;
72
    }
73
}