Completed
Push — master ( 8b4718...61d59f )
by Oleg
02:27
created

Result::setPayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @abstract API client for Optimizely.
4
 * @author Oleg Krivtsov <[email protected]>
5
 * @date 14 November 2016
6
 * @copyright (c) 2016, Web Marketing ROI
7
 */
8
namespace WebMarketingROI\OptimizelyPHP;
9
10
/**
11
 * Contains parsed response from Optimizely API.
12
 */
13
class Result
14
{
15
    /**
16
     * HTTP code.
17
     * @var integer
18
     */
19
    private $httpCode;
20
    
21
    /**
22
     * Payload.
23
     * @var mixed
24
     */
25
    private $payload = null;
26
    
27
    /**
28
     * Previous page number (or null).
29
     * @var integer|null
30
     */
31
    private $prevPage = null;
32
    
33
    /**
34
     * Next page number (or null).
35
     * @var integer|null
36
     */
37
    private $nextPage = null;
38
    
39
    /**
40
     * Last page number
41
     * @var integer|null
42
     */
43
    private $lastPage = null;
44
    
45
    /**
46
     * The limit for this endpoint
47
     * @var integer
48
     */
49
    private $rateLimit;
50
    
51
    /**
52
     * The amount of calls remaining for this endpoint
53
     * @var integer
54
     */
55
    private $rateLimitRemaining;
56
    
57
    /**
58
     * The X-RateLimit-Reset header provides a Unix UTC timestamp, letting you 
59
     * know the exact time that your fresh new rate limit kicks in.
60
     * @var string
61
     */
62
    private $rateLimitReset;
63
    
64
    /**
65
     * Decoded JSON response data.
66
     * @var array
67
     */
68
    private $decodedJsonData = null;
69
    
70
    /**
71
     * Constructor.
72
     * @param array $decodedJsonData
73
     * @param string $rawHttpResponseData
0 ignored issues
show
Bug introduced by
There is no parameter named $rawHttpResponseData. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
74
     * @param array[string] $rawHttpResponseHeaders
0 ignored issues
show
Documentation introduced by
The doc-type array[string] could not be parsed: Expected "]" at position 2, but found "string". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
Bug introduced by
There is no parameter named $rawHttpResponseHeaders. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
75
     */
76 32
    public function __construct($decodedJsonData, $httpCode)
77
    {
78 32
        $this->setDecodedJsonData($decodedJsonData);
79 32
        $this->setHttpCode($httpCode);
80 32
    }
81
    
82
    /**
83
     * Return HTTP response code.
84
     * @return integer
85
     */
86 4
    public function getHttpCode()
87
    {
88 4
        return $this->httpCode;
89
    }
90
            
91
    /**
92
     * Set HTTP response code.
93
     * @param integer $code
0 ignored issues
show
Bug introduced by
There is no parameter named $code. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
94
     */
95 32
    public function setHttpCode($httpCode)
96
    {
97 32
        $this->httpCode = $httpCode;
98 32
    }
99
    
100
    /**
101
     * Return payload.
102
     * @return mixed
103
     */
104 30
    public function getPayload()
105
    {
106 30
        return $this->payload;
107
    }
108
    
109
    /**
110
     * Set payload (parsed and wrapped response data).
111
     * @param mixed $payload
112
     */
113 29
    public function setPayload($payload)
114
    {
115 29
        $this->payload = $payload;
116 29
    }
117
    
118
    /**
119
     * Return decoded JSON data.
120
     * @return array
121
     */
122 29
    public function getDecodedJsonData()
123
    {
124 29
        return $this->decodedJsonData;
125
    }
126
    
127
    /**
128
     * Set decoded JSON data.
129
     * @param array $decodedJsonData
130
     */
131 32
    public function setDecodedJsonData($decodedJsonData)
132
    {
133 32
        $this->decodedJsonData = $decodedJsonData;
134 32
    }
135
    
136
    /**
137
     * Returns previous page number (or null).
138
     * @return integer|null
139
     */
140 1
    public function getPrevPage()
141
    {
142 1
        return $this->prevPage;
143
    }
144
    
145
    /**
146
     * Set previous page number.
147
     * @param integer|null $prevPage
148
     */
149 1
    public function setPrevPage($prevPage)
150
    {
151 1
        $this->prevPage = $prevPage;
152 1
    }
153
    
154
    /**
155
     * Returns next page number (or null).
156
     * @return integer|null
157
     */
158 1
    public function getNextPage()
159
    {
160 1
        return $this->nextPage;
161
    }
162
    
163
    /**
164
     * Set next page number.
165
     * @param integer|null $nextPage
166
     */
167 1
    public function setNextPage($nextPage)
168
    {
169 1
        $this->nextPage = $nextPage;
170 1
    }
171
    
172
    /**
173
     * Return last page number
174
     * @return integer|null
175
     */
176 1
    public function getLastPage()
177
    {
178 1
        return $this->lastPage;
179
    }
180
    
181
    /**
182
     * Set last page number.
183
     * @param integer|null $lastPage
184
     */
185 1
    public function setLastPage($lastPage)
186
    {
187 1
        $this->lastPage = $lastPage;
188 1
    }
189
    
190
    /**
191
     * Return rate limit.
192
     * @return integer|null
193
     */
194 1
    public function getRateLimit()
195
    {
196 1
        return $this->rateLimit;
197
    }
198
    
199
    /**
200
     * Set rate limit.
201
     * @param integer|null $rateLimit
202
     */
203 1
    public function setRateLimit($rateLimit)
204
    {
205 1
        $this->rateLimit = $rateLimit;
206 1
    }
207
    
208
    /**
209
     * Return the amount of calls remaining.
210
     * @return integer|null
211
     */
212 1
    public function getRateLimitRemaining()
213
    {
214 1
        return $this->rateLimitRemaining;
215
    }
216
    
217
    /**
218
     * Set the amount of calls remaining.
219
     * @param integer|null $rateLimitRemaining
220
     */
221 1
    public function setRateLimitRemaining($rateLimitRemaining)
222
    {
223 1
        $this->rateLimitRemaining = $rateLimitRemaining;
224 1
    }
225
    
226
    /**
227
     * Return the exact time that your fresh new rate limit kicks in.
228
     * @return integer|null
229
     */
230 1
    public function getRateLimitReset()
231
    {
232 1
        return $this->rateLimitReset;
233
    }
234
    
235
    /**
236
     * Set the exact time that your fresh new rate limit kicks in.
237
     * @param integer|null $rateLimitReset
238
     */
239 1
    public function setRateLimitReset($rateLimitReset)
240
    {
241 1
        $this->rateLimitReset = $rateLimitReset;
0 ignored issues
show
Documentation Bug introduced by
It seems like $rateLimitReset can also be of type integer. However, the property $rateLimitReset is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
242 1
    }
243
}
244
245
246