@@ -12,8 +12,8 @@ |
||
| 12 | 12 | class Client { |
| 13 | 13 | |
| 14 | 14 | const AUTH_DOMAIN = 'https://accounts.lifeboat.app'; |
| 15 | - const TOKEN_URL = self::AUTH_DOMAIN . '/oauth/api_token'; |
|
| 16 | - const SITES_URL = self::AUTH_DOMAIN . '/oauth/sites'; |
|
| 15 | + const TOKEN_URL = self::AUTH_DOMAIN.'/oauth/api_token'; |
|
| 16 | + const SITES_URL = self::AUTH_DOMAIN.'/oauth/sites'; |
|
| 17 | 17 | |
| 18 | 18 | private $_api_key = ''; |
| 19 | 19 | private $_api_secret = ''; |
@@ -40,7 +40,9 @@ |
||
| 40 | 40 | public function getJSON(): ?array |
| 41 | 41 | { |
| 42 | 42 | $data = json_decode($this->result, true); |
| 43 | - if (!is_array($data)) return null; |
|
| 43 | + if (!is_array($data)) { |
|
| 44 | + return null; |
|
| 45 | + } |
|
| 44 | 46 | |
| 45 | 47 | return $data; |
| 46 | 48 | } |
@@ -38,9 +38,15 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public function __construct(string $url = null, array $data = [], array $headers = []) |
| 40 | 40 | { |
| 41 | - if (!is_null($url)) $this->setURL($url); |
|
| 42 | - foreach ($data as $name => $value) $this->addDataParam($name, $value); |
|
| 43 | - foreach ($headers as $name => $value) $this->addHeader($name, $value); |
|
| 41 | + if (!is_null($url)) { |
|
| 42 | + $this->setURL($url); |
|
| 43 | + } |
|
| 44 | + foreach ($data as $name => $value) { |
|
| 45 | + $this->addDataParam($name, $value); |
|
| 46 | + } |
|
| 47 | + foreach ($headers as $name => $value) { |
|
| 48 | + $this->addHeader($name, $value); |
|
| 49 | + } |
|
| 44 | 50 | } |
| 45 | 51 | |
| 46 | 52 | /** |
@@ -97,7 +103,9 @@ discard block |
||
| 97 | 103 | |
| 98 | 104 | public function removeDataParam(string $name): Curl |
| 99 | 105 | { |
| 100 | - if (array_key_exists($name, $this->_data)) unset($this->_data[$name]); |
|
| 106 | + if (array_key_exists($name, $this->_data)) { |
|
| 107 | + unset($this->_data[$name]); |
|
| 108 | + } |
|
| 101 | 109 | return $this; |
| 102 | 110 | } |
| 103 | 111 | |
@@ -126,7 +134,9 @@ discard block |
||
| 126 | 134 | */ |
| 127 | 135 | public function removeHeader(string $name): Curl |
| 128 | 136 | { |
| 129 | - if (array_key_exists($name, $this->_headers)) unset($this->_headers[$name]); |
|
| 137 | + if (array_key_exists($name, $this->_headers)) { |
|
| 138 | + unset($this->_headers[$name]); |
|
| 139 | + } |
|
| 130 | 140 | return $this; |
| 131 | 141 | } |
| 132 | 142 | |
@@ -170,13 +180,17 @@ discard block |
||
| 170 | 180 | $request_uri = $this->getURL(); |
| 171 | 181 | |
| 172 | 182 | // Headers |
| 173 | - foreach ($this->getHeaders() as $k => $v) $send_headers[] = "{$k}: {$v}"; |
|
| 183 | + foreach ($this->getHeaders() as $k => $v) { |
|
| 184 | + $send_headers[] = "{$k}: {$v}"; |
|
| 185 | + } |
|
| 174 | 186 | |
| 175 | 187 | // Request Data |
| 176 | 188 | switch ($this->getMethod()) { |
| 177 | 189 | case 'GET': |
| 178 | 190 | case 'DELETE': |
| 179 | - foreach ($this->getDataParams() as $name => $value) $request_uri = $this->setGetVar($name, $value, $request_uri); |
|
| 191 | + foreach ($this->getDataParams() as $name => $value) { |
|
| 192 | + $request_uri = $this->setGetVar($name, $value, $request_uri); |
|
| 193 | + } |
|
| 180 | 194 | break; |
| 181 | 195 | |
| 182 | 196 | case 'POST': |
@@ -207,7 +221,9 @@ discard block |
||
| 207 | 221 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
| 208 | 222 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
| 209 | 223 | |
| 210 | - if (!empty($send_headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers); |
|
| 224 | + if (!empty($send_headers)) { |
|
| 225 | + curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers); |
|
| 226 | + } |
|
| 211 | 227 | if (!is_null($post_data)) { |
| 212 | 228 | curl_setopt($ch, CURLOPT_POST, 1); |
| 213 | 229 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); |
@@ -217,7 +233,9 @@ discard block |
||
| 217 | 233 | $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 218 | 234 | |
| 219 | 235 | $response = new CurlResponse($http_code, $result); |
| 220 | - if ($this->_enable_cache && isset($cache_key)) self::$_cache[$cache_key] = $response; |
|
| 236 | + if ($this->_enable_cache && isset($cache_key)) { |
|
| 237 | + self::$_cache[$cache_key] = $response; |
|
| 238 | + } |
|
| 221 | 239 | |
| 222 | 240 | return $response; |
| 223 | 241 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | if ($this->_enable_cache && $this->getMethod() === 'GET') { |
| 191 | - $cache_key = urlencode($request_uri) . implode(',', $send_headers); |
|
| 191 | + $cache_key = urlencode($request_uri).implode(',', $send_headers); |
|
| 192 | 192 | if (array_key_exists($cache_key, self::$_cache)) { |
| 193 | 193 | return self::$_cache[$cache_key]; |
| 194 | 194 | } |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
| 209 | 209 | |
| 210 | 210 | if (!empty($send_headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers); |
| 211 | - if (!is_null($post_data)) { |
|
| 211 | + if (!is_null($post_data)) { |
|
| 212 | 212 | curl_setopt($ch, CURLOPT_POST, 1); |
| 213 | 213 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); |
| 214 | 214 | } |
@@ -245,15 +245,15 @@ discard block |
||
| 245 | 245 | { |
| 246 | 246 | if (!self::is_absolute_url($url)) { |
| 247 | 247 | $isRelative = true; |
| 248 | - $url = 'http://dummy.com/' . ltrim($url, '/'); |
|
| 249 | - } else { |
|
| 248 | + $url = 'http://dummy.com/'.ltrim($url, '/'); |
|
| 249 | + }else { |
|
| 250 | 250 | $isRelative = false; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | // try to parse uri |
| 254 | 254 | $parts = parse_url($url); |
| 255 | 255 | if (!$parts) { |
| 256 | - throw new InvalidArgumentException("Can't parse URL: " . $url); |
|
| 256 | + throw new InvalidArgumentException("Can't parse URL: ".$url); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // Parse params and add new variable |
@@ -269,21 +269,21 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | if ($user != '') { |
| 271 | 271 | // format in either user:[email protected] or [email protected] |
| 272 | - $user .= (isset($parts['pass']) && $parts['pass'] != '') ? ':' . $parts['pass'] . '@' : '@'; |
|
| 272 | + $user .= (isset($parts['pass']) && $parts['pass'] != '') ? ':'.$parts['pass'].'@' : '@'; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | $host = (isset($parts['host'])) ? $parts['host'] : ''; |
| 276 | - $port = (isset($parts['port']) && $parts['port'] != '') ? ':' . $parts['port'] : ''; |
|
| 276 | + $port = (isset($parts['port']) && $parts['port'] != '') ? ':'.$parts['port'] : ''; |
|
| 277 | 277 | $path = (isset($parts['path']) && $parts['path'] != '') ? $parts['path'] : ''; |
| 278 | 278 | |
| 279 | 279 | // handle URL params which are existing / new |
| 280 | - $params = ($params) ? '?' . http_build_query($params, null, $separator) : ''; |
|
| 280 | + $params = ($params) ? '?'.http_build_query($params, null, $separator) : ''; |
|
| 281 | 281 | |
| 282 | 282 | // keep fragments (anchors) intact. |
| 283 | - $fragment = (isset($parts['fragment']) && $parts['fragment'] != '') ? '#' . $parts['fragment'] : ''; |
|
| 283 | + $fragment = (isset($parts['fragment']) && $parts['fragment'] != '') ? '#'.$parts['fragment'] : ''; |
|
| 284 | 284 | |
| 285 | 285 | // Recompile URI segments |
| 286 | - $newUri = $scheme . '://' . $user . $host . $port . $path . $params . $fragment; |
|
| 286 | + $newUri = $scheme.'://'.$user.$host.$port.$path.$params.$fragment; |
|
| 287 | 287 | |
| 288 | 288 | if ($isRelative) { |
| 289 | 289 | return str_replace('http://dummy.com/', '', $newUri); |
@@ -300,10 +300,10 @@ discard block |
||
| 300 | 300 | { |
| 301 | 301 | // Strip off the query and fragment parts of the URL before checking |
| 302 | 302 | if (($queryPosition = strpos($url, '?')) !== false) { |
| 303 | - $url = substr($url, 0, $queryPosition - 1); |
|
| 303 | + $url = substr($url, 0, $queryPosition-1); |
|
| 304 | 304 | } |
| 305 | 305 | if (($hashPosition = strpos($url, '#')) !== false) { |
| 306 | - $url = substr($url, 0, $hashPosition - 1); |
|
| 306 | + $url = substr($url, 0, $hashPosition-1); |
|
| 307 | 307 | } |
| 308 | 308 | $colonPosition = strpos($url, ':'); |
| 309 | 309 | $slashPosition = strpos($url, '/'); |