@@ -39,8 +39,12 @@ discard block |
||
| 39 | 39 | public function __construct(string $url, array $data = [], array $headers = []) |
| 40 | 40 | { |
| 41 | 41 | $this->setURL($url); |
| 42 | - foreach ($data as $name => $value) $this->addDataParam($name, $value); |
|
| 43 | - foreach ($headers as $name => $value) $this->addHeader($name, $value); |
|
| 42 | + foreach ($data as $name => $value) { |
|
| 43 | + $this->addDataParam($name, $value); |
|
| 44 | + } |
|
| 45 | + foreach ($headers as $name => $value) { |
|
| 46 | + $this->addHeader($name, $value); |
|
| 47 | + } |
|
| 44 | 48 | } |
| 45 | 49 | |
| 46 | 50 | /** |
@@ -99,7 +103,9 @@ discard block |
||
| 99 | 103 | |
| 100 | 104 | public function removeDataParam(string $name): Curl |
| 101 | 105 | { |
| 102 | - 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 | + } |
|
| 103 | 109 | return $this; |
| 104 | 110 | } |
| 105 | 111 | |
@@ -128,7 +134,9 @@ discard block |
||
| 128 | 134 | */ |
| 129 | 135 | public function removeHeader(string $name): Curl |
| 130 | 136 | { |
| 131 | - 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 | + } |
|
| 132 | 140 | return $this; |
| 133 | 141 | } |
| 134 | 142 | |
@@ -173,13 +181,17 @@ discard block |
||
| 173 | 181 | $request_uri = $this->getURL(); |
| 174 | 182 | |
| 175 | 183 | // Headers |
| 176 | - foreach ($this->getHeaders() as $k => $v) $send_headers[] = "{$k}: {$v}"; |
|
| 184 | + foreach ($this->getHeaders() as $k => $v) { |
|
| 185 | + $send_headers[] = "{$k}: {$v}"; |
|
| 186 | + } |
|
| 177 | 187 | |
| 178 | 188 | // Request Data |
| 179 | 189 | switch ($this->getMethod()) { |
| 180 | 190 | case 'GET': |
| 181 | 191 | case 'DELETE': |
| 182 | - foreach ($this->getDataParams() as $name => $value) $request_uri = URL::setGetVar($name, $value, $request_uri); |
|
| 192 | + foreach ($this->getDataParams() as $name => $value) { |
|
| 193 | + $request_uri = URL::setGetVar($name, $value, $request_uri); |
|
| 194 | + } |
|
| 183 | 195 | break; |
| 184 | 196 | |
| 185 | 197 | case 'POST': |
@@ -210,7 +222,9 @@ discard block |
||
| 210 | 222 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
| 211 | 223 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
| 212 | 224 | |
| 213 | - if (!empty($send_headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers); |
|
| 225 | + if (!empty($send_headers)) { |
|
| 226 | + curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers); |
|
| 227 | + } |
|
| 214 | 228 | if (!is_null($post_data)) { |
| 215 | 229 | curl_setopt($ch, CURLOPT_POST, 1); |
| 216 | 230 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); |
@@ -219,10 +233,14 @@ discard block |
||
| 219 | 233 | $result = curl_exec($ch); |
| 220 | 234 | $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 221 | 235 | |
| 222 | - if ($http_code === 401 && $retry_on_401) return $this->curl(false); |
|
| 236 | + if ($http_code === 401 && $retry_on_401) { |
|
| 237 | + return $this->curl(false); |
|
| 238 | + } |
|
| 223 | 239 | |
| 224 | 240 | $response = new CurlResponse((int) $http_code, (string) $result); |
| 225 | - if ($this->_enable_cache && isset($cache_key)) self::$_cache[$cache_key] = $response; |
|
| 241 | + if ($this->_enable_cache && isset($cache_key)) { |
|
| 242 | + self::$_cache[$cache_key] = $response; |
|
| 243 | + } |
|
| 226 | 244 | |
| 227 | 245 | return $response; |
| 228 | 246 | } |
@@ -115,7 +115,9 @@ |
||
| 115 | 115 | $sites = $this->app->getSites(); |
| 116 | 116 | |
| 117 | 117 | // If the user doesn't have access to any Lifeboat site force a re-auth |
| 118 | - if (count($sites) < 1) return $this->reloadAuth(); |
|
| 118 | + if (count($sites) < 1) { |
|
| 119 | + return $this->reloadAuth(); |
|
| 120 | + } |
|
| 119 | 121 | |
| 120 | 122 | // If the user only has access to one Lifeboat site then automatically use that |
| 121 | 123 | if (count($sites) === 1) { |
@@ -115,7 +115,9 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | public function getAPIChallenge(bool $check_session = true): string |
| 117 | 117 | { |
| 118 | - if ($this->_api_challenge) return $this->_api_challenge; |
|
| 118 | + if ($this->_api_challenge) { |
|
| 119 | + return $this->_api_challenge; |
|
| 120 | + } |
|
| 119 | 121 | |
| 120 | 122 | if ($check_session && session_status() === PHP_SESSION_ACTIVE) { |
| 121 | 123 | $this->setAPIChallenge($_SESSION[self::API_CHALLENGE_PARAM] ?? ''); |
@@ -162,7 +164,9 @@ discard block |
||
| 162 | 164 | $json = $response->getJSON(); |
| 163 | 165 | |
| 164 | 166 | if (!$response->isValid() || !$json || !array_key_exists('access_token', $json)) { |
| 165 | - if (array_key_exists('error', $json)) throw new OAuthException($json['error']); |
|
| 167 | + if (array_key_exists('error', $json)) { |
|
| 168 | + throw new OAuthException($json['error']); |
|
| 169 | + } |
|
| 166 | 170 | return ''; |
| 167 | 171 | } else { |
| 168 | 172 | $this->setAccessToken($json['access_token']); |
@@ -184,7 +188,9 @@ discard block |
||
| 184 | 188 | */ |
| 185 | 189 | public function getAccessToken(bool $check_session = true): string |
| 186 | 190 | { |
| 187 | - if ($this->_access_token) return $this->_access_token; |
|
| 191 | + if ($this->_access_token) { |
|
| 192 | + return $this->_access_token; |
|
| 193 | + } |
|
| 188 | 194 | |
| 189 | 195 | if ($check_session && session_status() === PHP_SESSION_ACTIVE) { |
| 190 | 196 | $this->setAccessToken($_SESSION[self::ACCESS_TOKEN_PARAM] ?? ''); |
@@ -60,7 +60,9 @@ discard block |
||
| 60 | 60 | public function __get(string $service): ?ApiService |
| 61 | 61 | { |
| 62 | 62 | $obj = ServiceFactory::inst($this, $service); |
| 63 | - if (!$obj) throw new BadMethodException("Service for `{$service}` does not exist"); |
|
| 63 | + if (!$obj) { |
|
| 64 | + throw new BadMethodException("Service for `{$service}` does not exist"); |
|
| 65 | + } |
|
| 64 | 66 | |
| 65 | 67 | return $obj; |
| 66 | 68 | } |
@@ -118,7 +120,9 @@ discard block |
||
| 118 | 120 | */ |
| 119 | 121 | public function getHost(): ?string |
| 120 | 122 | { |
| 121 | - if (!$this->getActiveSite(true)) return null; |
|
| 123 | + if (!$this->getActiveSite(true)) { |
|
| 124 | + return null; |
|
| 125 | + } |
|
| 122 | 126 | return $this->_host; |
| 123 | 127 | } |
| 124 | 128 | |
@@ -127,7 +131,9 @@ discard block |
||
| 127 | 131 | */ |
| 128 | 132 | public function getSiteKey(): ?string |
| 129 | 133 | { |
| 130 | - if (!$this->getActiveSite(true)) return null; |
|
| 134 | + if (!$this->getActiveSite(true)) { |
|
| 135 | + return null; |
|
| 136 | + } |
|
| 131 | 137 | return $this->_site_key; |
| 132 | 138 | } |
| 133 | 139 | |
@@ -151,7 +157,9 @@ discard block |
||
| 151 | 157 | $curl->addHeader('Host', $this->getHost()); |
| 152 | 158 | |
| 153 | 159 | foreach ($this->getAuthHeaders() as $header => $value) { |
| 154 | - if ($value) $curl->addHeader($header, $value); |
|
| 160 | + if ($value) { |
|
| 161 | + $curl->addHeader($header, $value); |
|
| 162 | + } |
|
| 155 | 163 | } |
| 156 | 164 | |
| 157 | 165 | return $curl->curl_json(); |
@@ -163,8 +171,12 @@ discard block |
||
| 163 | 171 | */ |
| 164 | 172 | public function getAuthHeaders(): array |
| 165 | 173 | { |
| 166 | - if (!$this->getAccessToken()) $this->fetchAccessToken(); |
|
| 167 | - if (!$this->getAccessToken()) throw new OAuthException("Access token has not been retreived"); |
|
| 174 | + if (!$this->getAccessToken()) { |
|
| 175 | + $this->fetchAccessToken(); |
|
| 176 | + } |
|
| 177 | + if (!$this->getAccessToken()) { |
|
| 178 | + throw new OAuthException("Access token has not been retreived"); |
|
| 179 | + } |
|
| 168 | 180 | |
| 169 | 181 | return [ |
| 170 | 182 | 'access-token' => $this->getAccessToken(), |