HetrixtoolsServiceResponse::fromJson()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 4
eloc 8
c 2
b 1
f 0
nc 4
nop 1
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 4
rs 10
1
<?php
2
3
namespace Azine\MailgunWebhooksBundle\Services\HetrixtoolsService;
4
5
class HetrixtoolsServiceResponse
6
{
7
    const RESPONSE_STATUS_SUCCESS = 'SUCCESS';
8
    const RESPONSE_STATUS_ERROR = 'ERROR';
9
    const BLACKLIST_CHECK_IN_PROGRESS = 'blacklist check in progress for this ipv4';
10
11
    /**
12
     * @var string
13
     */
14
    public $status;
15
16
    /**
17
     * @var int
18
     */
19
    public $api_calls_left;
20
21
    /**
22
     * @var int
23
     */
24
    public $blacklist_check_credits_left;
25
26
    /**
27
     * @var int
28
     */
29
    public $blacklisted_count;
30
31
    /**
32
     * @var array
33
     */
34
    public $blacklisted_on;
35
36
    /**
37
     * @var array
38
     */
39
    public $links;
40
41
    /**
42
     * @var string
43
     */
44
    public $error_message;
45
46
    /**
47
     * @param string $response
48
     *
49
     * @throws \InvalidArgumentException
50
     *
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) {
64 2
            if (isset($response[$key])) {
65 2
                $responseObject->$key = $response[$key];
66
            }
67
        }
68
69 2
        return $responseObject;
70
    }
71
}
72