|
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 error/exception information returned by Optimizely API. |
|
12
|
|
|
*/ |
|
13
|
|
|
class Exception extends \Exception |
|
14
|
|
|
{ |
|
15
|
|
|
// Error codes returned as part of exception information. |
|
16
|
|
|
const CODE_INVALID_ARG = -1; // Invalid argument passed. |
|
17
|
|
|
const CODE_CURL_ERROR = -2; // Some error in CURL. |
|
18
|
|
|
const CODE_API_ERROR = -3; // Some error condition returned by Optimizely API. |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* HTTP response code. |
|
22
|
|
|
* @var integer |
|
23
|
|
|
*/ |
|
24
|
|
|
private $httpCode; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Error UUID extracted from response JSON. |
|
28
|
|
|
* @var type |
|
29
|
|
|
*/ |
|
30
|
|
|
private $uuid; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The limit for this endpoint |
|
34
|
|
|
* @var integer |
|
35
|
|
|
*/ |
|
36
|
|
|
private $rateLimit; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* The amount of calls remaining for this endpoint |
|
40
|
|
|
* @var integer |
|
41
|
|
|
*/ |
|
42
|
|
|
private $rateLimitRemaining; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The X-RateLimit-Reset header provides a Unix UTC timestamp, letting you |
|
46
|
|
|
* know the exact time that your fresh new rate limit kicks in. |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
private $rateLimitReset; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Constructor. |
|
53
|
|
|
*/ |
|
54
|
3 |
|
public function __construct($message, $code = self::CODE_INVALID_ARG, $options = array()) |
|
55
|
|
|
{ |
|
56
|
3 |
|
parent::__construct($message, $code); |
|
57
|
|
|
|
|
58
|
3 |
|
if (isset($options['http_code'])) |
|
59
|
3 |
|
$this->setHttpCode($options['http_code']); |
|
60
|
|
|
|
|
61
|
3 |
|
if (isset($options['uuid'])) |
|
62
|
3 |
|
$this->setUuid($options['uuid']); |
|
63
|
|
|
|
|
64
|
3 |
|
if (isset($options['rate_limit'])) |
|
65
|
3 |
|
$this->setRateLimit($options['rate_limit']); |
|
66
|
|
|
|
|
67
|
3 |
|
if (isset($options['rate_limit_remaining'])) |
|
68
|
3 |
|
$this->setRateLimitRemaining($options['rate_limit_remaining']); |
|
69
|
|
|
|
|
70
|
3 |
|
if (isset($options['rate_limit_reset'])) |
|
71
|
3 |
|
$this->setRateLimitReset($options['rate_limit_reset']); |
|
72
|
3 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Return HTTP response code. |
|
76
|
|
|
* @return integer |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getHttpCode() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->httpCode; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Set HTTP response code. |
|
85
|
|
|
* @param integer $code |
|
|
|
|
|
|
86
|
|
|
*/ |
|
87
|
1 |
|
public function setHttpCode($httpCode) |
|
88
|
|
|
{ |
|
89
|
1 |
|
$this->httpCode = $httpCode; |
|
90
|
1 |
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Return error UUID. |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getUuid() |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->uuid; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Set message |
|
103
|
|
|
* @param string $message |
|
|
|
|
|
|
104
|
|
|
*/ |
|
105
|
|
|
public function setUuid($uuid) |
|
106
|
|
|
{ |
|
107
|
|
|
$this->uuid = $uuid; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getRateLimit() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->rateLimit; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function setRateLimit($rateLimit) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->rateLimit = $rateLimit; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function getRateLimitRemaining() |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->rateLimitRemaining; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function setRateLimitRemaining($rateLimitRemaining) |
|
126
|
|
|
{ |
|
127
|
|
|
$this->rateLimitRemaining = $rateLimitRemaining; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function getRateLimitReset() |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->rateLimitReset; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function setRateLimitReset($rateLimitReset) |
|
136
|
|
|
{ |
|
137
|
|
|
$this->rateLimitReset = $rateLimitReset; |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
|
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.