@@ -40,8 +40,12 @@ discard block |
||
| 40 | 40 | public function __construct(string $url, array $data = [], array $headers = []) |
| 41 | 41 | { |
| 42 | 42 | $this->setURL($url); |
| 43 | - foreach ($data as $name => $value) $this->addDataParam($name, $value); |
|
| 44 | - foreach ($headers as $name => $value) $this->addHeader($name, $value); |
|
| 43 | + foreach ($data as $name => $value) { |
|
| 44 | + $this->addDataParam($name, $value); |
|
| 45 | + } |
|
| 46 | + foreach ($headers as $name => $value) { |
|
| 47 | + $this->addHeader($name, $value); |
|
| 48 | + } |
|
| 45 | 49 | } |
| 46 | 50 | |
| 47 | 51 | /** |
@@ -100,7 +104,9 @@ discard block |
||
| 100 | 104 | |
| 101 | 105 | public function removeDataParam(string $name): Curl |
| 102 | 106 | { |
| 103 | - if (array_key_exists($name, $this->_data)) unset($this->_data[$name]); |
|
| 107 | + if (array_key_exists($name, $this->_data)) { |
|
| 108 | + unset($this->_data[$name]); |
|
| 109 | + } |
|
| 104 | 110 | return $this; |
| 105 | 111 | } |
| 106 | 112 | |
@@ -129,7 +135,9 @@ discard block |
||
| 129 | 135 | */ |
| 130 | 136 | public function removeHeader(string $name): Curl |
| 131 | 137 | { |
| 132 | - if (array_key_exists($name, $this->_headers)) unset($this->_headers[$name]); |
|
| 138 | + if (array_key_exists($name, $this->_headers)) { |
|
| 139 | + unset($this->_headers[$name]); |
|
| 140 | + } |
|
| 133 | 141 | return $this; |
| 134 | 142 | } |
| 135 | 143 | |
@@ -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); |
@@ -220,7 +234,9 @@ discard block |
||
| 220 | 234 | $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 221 | 235 | |
| 222 | 236 | $response = new CurlResponse((int) $http_code, (string) $result); |
| 223 | - if ($this->_enable_cache && isset($cache_key)) self::$_cache[$cache_key] = $response; |
|
| 237 | + if ($this->_enable_cache && isset($cache_key)) { |
|
| 238 | + self::$_cache[$cache_key] = $response; |
|
| 239 | + } |
|
| 224 | 240 | |
| 225 | 241 | return $response; |
| 226 | 242 | } |
@@ -129,16 +129,22 @@ discard block |
||
| 129 | 129 | $response = $this->getClient()->curl_api($this->getURL(), 'GET', $data); |
| 130 | 130 | $data = ($response->isValid() && $response->isJSON()) ? $response->getJSON() : []; |
| 131 | 131 | |
| 132 | - if (empty($data)) throw new ApiException($response->getError()); |
|
| 132 | + if (empty($data)) { |
|
| 133 | + throw new ApiException($response->getError()); |
|
| 134 | + } |
|
| 133 | 135 | |
| 134 | 136 | $this->_max_items = (int) $data['available_items']; |
| 135 | 137 | |
| 136 | - if (empty($data['items'])) return $this->_items[$page] = []; |
|
| 138 | + if (empty($data['items'])) { |
|
| 139 | + return $this->_items[$page] = []; |
|
| 140 | + } |
|
| 137 | 141 | |
| 138 | 142 | |
| 139 | 143 | foreach ($data['items'] as $item) { |
| 140 | 144 | $obj = ObjectFactory::make($this->getClient(), $item); |
| 141 | - if (!$obj) continue; |
|
| 145 | + if (!$obj) { |
|
| 146 | + continue; |
|
| 147 | + } |
|
| 142 | 148 | |
| 143 | 149 | $this->_items[$page][] = $obj; |
| 144 | 150 | } |
@@ -153,7 +159,9 @@ discard block |
||
| 153 | 159 | */ |
| 154 | 160 | public function offsetGet($offset): ?ObjectResource |
| 155 | 161 | { |
| 156 | - foreach ($this as $i => $obj) if ($i === $offset) return $obj; |
|
| 162 | + foreach ($this as $i => $obj) { |
|
| 163 | + if ($i === $offset) return $obj; |
|
| 164 | + } |
|
| 157 | 165 | return null; |
| 158 | 166 | } |
| 159 | 167 | |
@@ -184,7 +192,9 @@ discard block |
||
| 184 | 192 | */ |
| 185 | 193 | public function offsetExists($offset): bool |
| 186 | 194 | { |
| 187 | - foreach ($this as $i => $obj) if ($offset === $i) return true; |
|
| 195 | + foreach ($this as $i => $obj) { |
|
| 196 | + if ($offset === $i) return true; |
|
| 197 | + } |
|
| 188 | 198 | return false; |
| 189 | 199 | } |
| 190 | 200 | |
@@ -240,6 +250,8 @@ discard block |
||
| 240 | 250 | */ |
| 241 | 251 | public function first(): ?Model |
| 242 | 252 | { |
| 243 | - foreach ($this as $obj) return $obj; |
|
| 253 | + foreach ($this as $obj) { |
|
| 254 | + return $obj; |
|
| 255 | + } |
|
| 244 | 256 | } |
| 245 | 257 | } |
@@ -109,7 +109,9 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function getAPIChallenge(bool $check_session = true): string |
| 111 | 111 | { |
| 112 | - if ($this->_api_challenge) return $this->_api_challenge; |
|
| 112 | + if ($this->_api_challenge) { |
|
| 113 | + return $this->_api_challenge; |
|
| 114 | + } |
|
| 113 | 115 | |
| 114 | 116 | if ($check_session && session_status() === PHP_SESSION_ACTIVE) { |
| 115 | 117 | $this->setAPIChallenge($_SESSION[self::API_CHALLENGE_PARAM] ?? ''); |
@@ -169,7 +171,9 @@ discard block |
||
| 169 | 171 | */ |
| 170 | 172 | public function getAccessToken(bool $check_session = true): string |
| 171 | 173 | { |
| 172 | - if ($this->_access_token) return $this->_access_token; |
|
| 174 | + if ($this->_access_token) { |
|
| 175 | + return $this->_access_token; |
|
| 176 | + } |
|
| 173 | 177 | |
| 174 | 178 | if ($check_session && session_status() === PHP_SESSION_ACTIVE) { |
| 175 | 179 | $this->setAccessToken($_SESSION[self::ACCESS_TOKEN_PARAM] ?? ''); |