@@ -16,7 +16,9 @@ |
||
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | function __invoke(string $url, array $header=[], array $body=null):array { |
| 19 | - if ($body != null) $body = json_encode($body); |
|
| 19 | + if ($body != null) { |
|
| 20 | + $body = json_encode($body); |
|
| 21 | + } |
|
| 20 | 22 | |
| 21 | 23 | $ch = curl_init($url); |
| 22 | 24 | |
@@ -10,7 +10,9 @@ |
||
| 10 | 10 | * @return string [description] |
| 11 | 11 | */ |
| 12 | 12 | function build_url_query(array $params, bool $urlEncode=true):?string { |
| 13 | - if ($params == null) return null; |
|
| 13 | + if ($params == null) { |
|
| 14 | + return null; |
|
| 15 | + } |
|
| 14 | 16 | $queryString = '?'; |
| 15 | 17 | foreach($params as $key => $val) { |
| 16 | 18 | if (is_array($val)) { |
@@ -22,7 +22,9 @@ discard block |
||
| 22 | 22 | get_instance()->load->splint('francis94c/ci-gmail', '%curl'); |
| 23 | 23 | get_instance()->load->splint('francis94c/ci-gmail', '%base64'); |
| 24 | 24 | |
| 25 | - if ($params != null) $this->init($params); |
|
| 25 | + if ($params != null) { |
|
| 26 | + $this->init($params); |
|
| 27 | + } |
|
| 26 | 28 | |
| 27 | 29 | spl_autoload_register(function($name) { |
| 28 | 30 | if (file_exists(APPPATH.'splints/'.self::PACKAGE."/libraries/$name.php")) { |
@@ -69,7 +71,9 @@ discard block |
||
| 69 | 71 | string $responseType='code', string $accessType='offline', bool $prompt=false):string |
| 70 | 72 | { |
| 71 | 73 | $redirectUri = $redirectUri ?? $this->redirectUri; |
| 72 | - if ($scope == null) throw new Exception("GMail scope cannot be null"); |
|
| 74 | + if ($scope == null) { |
|
| 75 | + throw new Exception("GMail scope cannot be null"); |
|
| 76 | + } |
|
| 73 | 77 | $params = [ |
| 74 | 78 | 'client_id' => $this->clientId, |
| 75 | 79 | 'redirect_uri' => $redirectUri, |
@@ -77,7 +81,9 @@ discard block |
||
| 77 | 81 | 'response_type' => $responseType, |
| 78 | 82 | 'access_type' => $accessType |
| 79 | 83 | ]; |
| 80 | - if ($prompt) $params['prompt'] = 'consent'; |
|
| 84 | + if ($prompt) { |
|
| 85 | + $params['prompt'] = 'consent'; |
|
| 86 | + } |
|
| 81 | 87 | return self::AUTH_URL . build_url_query($params, false); |
| 82 | 88 | } |
| 83 | 89 | /** |
@@ -115,7 +121,9 @@ discard block |
||
| 115 | 121 | curl_close($ch); |
| 116 | 122 | $this->lastResponse = $response; |
| 117 | 123 | $this->lastResponseCode = $code; |
| 118 | - if ($response !== false) return $this->process_response($code, $response); |
|
| 124 | + if ($response !== false) { |
|
| 125 | + return $this->process_response($code, $response); |
|
| 126 | + } |
|
| 119 | 127 | return null; |
| 120 | 128 | } |
| 121 | 129 | /** |
@@ -152,7 +160,9 @@ discard block |
||
| 152 | 160 | curl_close($ch); |
| 153 | 161 | $this->lastResponse = $response; |
| 154 | 162 | $this->lastResponseCode = $code; |
| 155 | - if ($response !== false) return $this->process_response($code, $response); |
|
| 163 | + if ($response !== false) { |
|
| 164 | + return $this->process_response($code, $response); |
|
| 165 | + } |
|
| 156 | 166 | return null; |
| 157 | 167 | } |
| 158 | 168 | /** |
@@ -169,7 +179,9 @@ discard block |
||
| 169 | 179 | ); |
| 170 | 180 | $this->lastResponse = $response; |
| 171 | 181 | $this->lastResponseCode = $code; |
| 172 | - if ($response !== false) return $this->process_response($code, $response); |
|
| 182 | + if ($response !== false) { |
|
| 183 | + return $this->process_response($code, $response); |
|
| 184 | + } |
|
| 173 | 185 | return null; |
| 174 | 186 | } |
| 175 | 187 | |
@@ -208,7 +220,9 @@ discard block |
||
| 208 | 220 | ); |
| 209 | 221 | $this->lastResponse = $response; |
| 210 | 222 | $this->lastResponseCode = $code; |
| 211 | - if ($response !== false) return $this->process_response($code, $response); |
|
| 223 | + if ($response !== false) { |
|
| 224 | + return $this->process_response($code, $response); |
|
| 225 | + } |
|
| 212 | 226 | return null; |
| 213 | 227 | } |
| 214 | 228 | |
@@ -226,7 +240,9 @@ discard block |
||
| 226 | 240 | ); |
| 227 | 241 | $this->lastResponse = $response; |
| 228 | 242 | $this->lastResponseCode = $code; |
| 229 | - if ($response !== false) return $code == 204; |
|
| 243 | + if ($response !== false) { |
|
| 244 | + return $code == 204; |
|
| 245 | + } |
|
| 230 | 246 | return false; |
| 231 | 247 | } |
| 232 | 248 | |
@@ -267,11 +283,21 @@ discard block |
||
| 267 | 283 | { |
| 268 | 284 | $query = []; |
| 269 | 285 | |
| 270 | - if ($labelIds != null) $query['labelIds'] = $labelIds; |
|
| 271 | - if ($includeSpamTrash) $query['includeSpamTrash'] = $includeSpamTrash; |
|
| 272 | - if ($q != null) $query['q'] = $q; |
|
| 273 | - if ($pageToken != null) $query['pageToken'] = $pageToken; |
|
| 274 | - if ($maxMessages != null) $query['maxResults'] = $maxMessages; |
|
| 286 | + if ($labelIds != null) { |
|
| 287 | + $query['labelIds'] = $labelIds; |
|
| 288 | + } |
|
| 289 | + if ($includeSpamTrash) { |
|
| 290 | + $query['includeSpamTrash'] = $includeSpamTrash; |
|
| 291 | + } |
|
| 292 | + if ($q != null) { |
|
| 293 | + $query['q'] = $q; |
|
| 294 | + } |
|
| 295 | + if ($pageToken != null) { |
|
| 296 | + $query['pageToken'] = $pageToken; |
|
| 297 | + } |
|
| 298 | + if ($maxMessages != null) { |
|
| 299 | + $query['maxResults'] = $maxMessages; |
|
| 300 | + } |
|
| 275 | 301 | |
| 276 | 302 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
| 277 | 303 | self::API . "$userId/messages" . build_url_query($query), |
@@ -310,8 +336,12 @@ discard block |
||
| 310 | 336 | { |
| 311 | 337 | $query = []; |
| 312 | 338 | |
| 313 | - if ($format != 'full' && $format != null) $query['format'] = $format; |
|
| 314 | - if ($metadataHeaders != null) $query['metadataHeaders'] = $metadataHeaders; |
|
| 339 | + if ($format != 'full' && $format != null) { |
|
| 340 | + $query['format'] = $format; |
|
| 341 | + } |
|
| 342 | + if ($metadataHeaders != null) { |
|
| 343 | + $query['metadataHeaders'] = $metadataHeaders; |
|
| 344 | + } |
|
| 315 | 345 | |
| 316 | 346 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
| 317 | 347 | self::API . "$userId/messages/$messageId?" . http_build_query($query), |
@@ -321,7 +351,9 @@ discard block |
||
| 321 | 351 | $this->lastResponse = $response; |
| 322 | 352 | $this->lastResponseCode = $code; |
| 323 | 353 | |
| 324 | - if ($response !== false) return new Message($response); |
|
| 354 | + if ($response !== false) { |
|
| 355 | + return new Message($response); |
|
| 356 | + } |
|
| 325 | 357 | |
| 326 | 358 | return null; |
| 327 | 359 | } |