Passed
Pull Request — master (#2)
by
unknown
02:15
created

CreateResponse::getExpirationDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

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
rs 10
1
<?php
2
3
/**
4
 * Part of the AmazonGiftCode package.
5
 * Author: Kashyap Merai <[email protected]>
6
 *
7
 */
8
9
10
namespace kamerk22\AmazonGiftCode\Response;
11
12
13
class CreateResponse
14
{
15
16
    /**
17
     * Amazon Gift Card gcId.
18
     *
19
     * @var string
20
     */
21
    protected $_id;
22
23
    /**
24
     * Amazon Gift Card creationRequestId
25
     *
26
     * @var string
27
     */
28
    protected $_creation_request_id;
29
30
    /**
31
     * Amazon Gift Card gcClaimCode
32
     *
33
     * @var string
34
     */
35
    protected $_claim_code;
36
37
    /**
38
     * Amazon Gift Card amount
39
     *
40
     * @var string
41
     */
42
    protected $_value;
43
44
    /**
45
     * Amazon Gift Card currency
46
     *
47
     * @var string
48
     */
49
    protected $_currency;
50
    /**
51
     * Amazon Gift Card status
52
     *
53
     * @var string
54
     */
55
    protected $_status;
56
    /**
57
     * Amazon Gift Card Expiration Date
58
     *
59
     * @var string
60
     */
61
    protected $_expiration_date;
62
63
    /**
64
     * Amazon Gift Card Raw JSON
65
     *
66
     * @var string
67
     */
68
    protected $_raw_json;
69
70
    /**
71
     * Response constructor.
72
     * @param $jsonResponse
73
     */
74
    public function __construct($jsonResponse)
75
    {
76
        $this->_raw_json = $jsonResponse;
77
        $this->_status = TRUE;
0 ignored issues
show
Documentation Bug introduced by
The property $_status was declared of type string, but TRUE is of type true. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
78
        $this->parseJsonResponse($jsonResponse);
79
    }
80
81
82
    /**
83
     * @return string
84
     */
85
    public function getId(): string
86
    {
87
        return $this->_id;
88
    }
89
90
    /**
91
     * @return string
92
     */
93
    public function getCreationRequestId(): string
94
    {
95
        return $this->_creation_request_id;
96
    }
97
98
99
    /**
100
     * @return string
101
     */
102
    public function getClaimCode(): string
103
    {
104
        return $this->_claim_code;
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    public function getValue(): string
111
    {
112
        return $this->_value;
113
    }
114
115
    /**
116
     * @return string
117
     */
118
    public function getCurrency(): string
119
    {
120
        return $this->_currency;
121
    }
122
123
    /**
124
     * @return string
125
     */
126
    public function getStatus(): string
127
    {
128
        return $this->_status;
129
    }
130
131
    /**
132
     * @return string
133
     */
134
    public function getExpirationDate(): string
135
    {
136
        return $this->_expiration_date;
137
    }
138
139
140
    /**
141
     * @return string
142
     */
143
    public function getRawJson(): string
144
    {
145
        return json_encode($this->_raw_json);
146
    }
147
148
    /**
149
     * @param $jsonResponse
150
     * @return CreateResponse
151
     */
152
    public function parseJsonResponse($jsonResponse): self
153
    {
154
        if (!is_array($jsonResponse)) {
155
            throw new \RuntimeException('Response must be a scalar value');
156
        }
157
        if (array_key_exists('gcId', $jsonResponse)) {
158
            $this->_id = $jsonResponse['gcId'];
159
        }
160
        if (array_key_exists('creationRequestId', $jsonResponse)) {
161
            $this->_creation_request_id = $jsonResponse['creationRequestId'];
162
        }
163
        if (array_key_exists('gcClaimCode', $jsonResponse)) {
164
            $this->_claim_code = $jsonResponse['gcClaimCode'];
165
        }
166
        if (array_key_exists('amount', $jsonResponse['cardInfo']['value'])) {
167
            $this->_value = $jsonResponse['cardInfo']['value']['amount'];
168
        }
169
        if (array_key_exists('currencyCode', $jsonResponse['cardInfo']['value'])) {
170
            $this->_currency = $jsonResponse['cardInfo']['value']['currencyCode'];
171
        }
172
        if (array_key_exists('gcExpirationDate', $jsonResponse)) {
173
            $this->_expiration_date = $jsonResponse['gcExpirationDate'];
174
        }
175
176
        return $this;
177
178
    }
179
180
}