Completed
Pull Request — master (#30)
by
unknown
05:39
created

HetrixtoolsServiceResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

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
12
    /**
13
     * @var string
14
     */
15
    public $status;
16
17
    /**
18
     * @var int
19
     */
20
    public $api_calls_left;
21
22
    /**
23
     * @var int
24
     */
25
    public $blacklist_check_credits_left;
26
27
    /**
28
     * @var int
29
     */
30
    public $blacklisted_count;
31
32
    /**
33
     * @var array
34
     */
35
    public $blacklisted_on;
36
37
    /**
38
     * @var array
39
     */
40
    public $links;
41
42
    /**
43
     * @var string
44
     */
45
    public $error_message;
46
47
    /**
48
     * @param string $response
49
     * @throws \InvalidArgumentException
50
     * @return HetrixtoolsServiceResponse $responseObject
51
     */
52 2
    public static function fromJson($response)
53
    {
54 2
        $response = json_decode($response, true);
55
56 2
        if(!is_array($response)) {
57 1
            throw new \InvalidArgumentException('Invalid JSON provided');
58
        }
59
60 1
        $responseObject = new self();
61
62 1
        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...
63
64 1
            if(isset($response[$key])){
65
66 1
                $responseObject->$key = $response[$key];
67 1
            }
68 1
        }
69
70 1
        return $responseObject;
71
    }
72
}