1 | <?php |
||
4 | class Base |
||
5 | { |
||
6 | const CLIENT_VERSION = '2.0.0'; |
||
7 | |||
8 | const HTTP_GET = 'GET'; |
||
9 | const HTTP_POST = 'POST'; |
||
10 | const HTTP_PUT = 'PUT'; |
||
11 | const HTTP_DELETE = 'DELETE'; |
||
12 | |||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $api_endpoint = 'https://api.datatrics.com/2.0'; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $api_key; |
||
22 | |||
23 | /** |
||
24 | * Base constructor. |
||
25 | * @param $apikey |
||
26 | * @param $endpoint |
||
27 | */ |
||
28 | 13 | public function __construct($apikey, $endpoint) |
|
33 | |||
34 | /** |
||
35 | * @return string |
||
36 | */ |
||
37 | protected function getApiEndpoint() |
||
41 | |||
42 | /** |
||
43 | * @param string $api_endpoint |
||
44 | * @return Base |
||
45 | */ |
||
46 | protected function setApiEndpoint($api_endpoint) |
||
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | protected function getApiKey() |
||
59 | |||
60 | /** |
||
61 | * @param string $api_key |
||
62 | * @return Base |
||
63 | */ |
||
64 | protected function setApiKey($api_key) |
||
69 | |||
70 | /** |
||
71 | * @throws \Exception |
||
72 | */ |
||
73 | 9 | public function checkApiKey() |
|
79 | |||
80 | /** |
||
81 | * @param $url |
||
82 | * @param null|array $payload |
||
83 | * @return string |
||
84 | */ |
||
85 | 6 | public function getUrl($url, $payload = null) |
|
93 | |||
94 | /** |
||
95 | * @param int $responseCode |
||
96 | * @param array $responseBody |
||
97 | * |
||
98 | * @throws \Exception |
||
99 | */ |
||
100 | 6 | private function handleResponseError($responseCode, $responseBody) |
|
114 | |||
115 | /** |
||
116 | * @param resource $curlHandle |
||
117 | * |
||
118 | * @throws \Exception |
||
119 | */ |
||
120 | private function handleCurlError($curlHandle) |
||
126 | |||
127 | /** |
||
128 | * Perform an http call. This method is used by the resource specific classes. |
||
129 | * |
||
130 | * @param $method |
||
131 | * @param $url |
||
132 | * @param $payload |
||
133 | * |
||
134 | * @return string|object |
||
135 | * |
||
136 | * @throws \Exception |
||
137 | */ |
||
138 | 7 | public function request($method, $url, $payload = null) |
|
205 | } |
||
206 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.