| @@ -17,7 +17,7 @@ discard block | ||
| 17 | 17 | private $lastResponse; | 
| 18 | 18 | private $lastResponseCode; | 
| 19 | 19 | |
| 20 | - function __construct($params=null) | |
| 20 | + function __construct($params = null) | |
| 21 | 21 |    { | 
| 22 | 22 |      get_instance()->load->splint('francis94c/ci-gmail', '%curl'); | 
| 23 | 23 |      get_instance()->load->splint('francis94c/ci-gmail', '%base64'); | 
| @@ -52,7 +52,7 @@ discard block | ||
| 52 | 52 | * [getClientId Get Client ID.] | 
| 53 | 53 | * @return null|string Client ID. | 
| 54 | 54 | */ | 
| 55 | -  public function getClientId():?string { | |
| 55 | +  public function getClientId(): ?string { | |
| 56 | 56 | return $this->clientId; | 
| 57 | 57 | } | 
| 58 | 58 | /** | 
| @@ -65,8 +65,8 @@ discard block | ||
| 65 | 65 | * @param bool $prompt Add the prompt=consent query to the URL. | 
| 66 | 66 | * @return string Authorize URL | 
| 67 | 67 | */ | 
| 68 | - public function getAuthorizeUrl(string $scope, string $redirectUri=null, | |
| 69 | - string $responseType='code', string $accessType='offline', bool $prompt=false):string | |
| 68 | + public function getAuthorizeUrl(string $scope, string $redirectUri = null, | |
| 69 | + string $responseType = 'code', string $accessType = 'offline', bool $prompt = false):string | |
| 70 | 70 |    { | 
| 71 | 71 | $redirectUri = $redirectUri ?? $this->redirectUri; | 
| 72 | 72 |      if ($scope == null) throw new Exception("GMail scope cannot be null"); | 
| @@ -78,14 +78,14 @@ discard block | ||
| 78 | 78 | 'access_type' => $accessType | 
| 79 | 79 | ]; | 
| 80 | 80 | if ($prompt) $params['prompt'] = 'consent'; | 
| 81 | - return self::AUTH_URL . build_url_query($params, false); | |
| 81 | + return self::AUTH_URL.build_url_query($params, false); | |
| 82 | 82 | } | 
| 83 | 83 | /** | 
| 84 | 84 | * [getToken description] | 
| 85 | 85 | * @param string $code [description] | 
| 86 | 86 | * @return [type] [description] | 
| 87 | 87 | */ | 
| 88 | - public function getToken(string $code, string $redirectUri=null):?object | |
| 88 | + public function getToken(string $code, string $redirectUri = null): ?object | |
| 89 | 89 |    { | 
| 90 | 90 | $redirectUri = $redirectUri ?? $this->redirectUri; | 
| 91 | 91 | $ch = curl_init(self::TOKEN_URL); | 
| @@ -103,7 +103,7 @@ discard block | ||
| 103 | 103 | ]); | 
| 104 | 104 | $header = [ | 
| 105 | 105 | 'Content-Type: application/x-www-form-urlencoded', | 
| 106 | - 'Content-Length: ' . strlen($body) | |
| 106 | + 'Content-Length: '.strlen($body) | |
| 107 | 107 | ]; | 
| 108 | 108 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | 
| 109 | 109 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); | 
| @@ -123,7 +123,7 @@ discard block | ||
| 123 | 123 | * @param string $refreshToken [description] | 
| 124 | 124 | * @return [type] [description] | 
| 125 | 125 | */ | 
| 126 | - public function refreshAccessToken(string $refreshToken):?object | |
| 126 | + public function refreshAccessToken(string $refreshToken): ?object | |
| 127 | 127 |    { | 
| 128 | 128 | $ch = curl_init(self::TOKEN_URL); | 
| 129 | 129 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | 
| @@ -139,7 +139,7 @@ discard block | ||
| 139 | 139 | ]); | 
| 140 | 140 | $header = [ | 
| 141 | 141 | 'Content-Type: application/x-www-form-urlencoded', | 
| 142 | - 'Content-Length: ' . strlen($body) | |
| 142 | + 'Content-Length: '.strlen($body) | |
| 143 | 143 | ]; | 
| 144 | 144 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | 
| 145 | 145 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); | 
| @@ -161,10 +161,10 @@ discard block | ||
| 161 | 161 | * @param string $user [description] | 
| 162 | 162 | * @return [type] [description] | 
| 163 | 163 | */ | 
| 164 | - public function getProfile(string $user='me'):?object | |
| 164 | + public function getProfile(string $user = 'me'): ?object | |
| 165 | 165 |    { | 
| 166 | 166 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( | 
| 167 | - self::API . "$user/profile", | |
| 167 | + self::API."$user/profile", | |
| 168 | 168 | ["Authorization: Bearer $this->token"] | 
| 169 | 169 | ); | 
| 170 | 170 | $this->lastResponse = $response; | 
| @@ -185,8 +185,8 @@ discard block | ||
| 185 | 185 | * @param string $labelFilterAction [description] | 
| 186 | 186 | * @return [type] [description] | 
| 187 | 187 | */ | 
| 188 | - public function watch(string $topic, $labelIds=null, string $userId='me', | |
| 189 | - string $labelFilterAction='include'):?object | |
| 188 | + public function watch(string $topic, $labelIds = null, string $userId = 'me', | |
| 189 | + string $labelFilterAction = 'include'): ?object | |
| 190 | 190 |    { | 
| 191 | 191 | $body = [ | 
| 192 | 192 | 'topicName' => $topic, | 
| @@ -202,7 +202,7 @@ discard block | ||
| 202 | 202 | } | 
| 203 | 203 | |
| 204 | 204 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( | 
| 205 | - self::API . "$userId/watch", | |
| 205 | + self::API."$userId/watch", | |
| 206 | 206 | ["Authorization: Bearer $this->token"], | 
| 207 | 207 | $body | 
| 208 | 208 | ); | 
| @@ -218,10 +218,10 @@ discard block | ||
| 218 | 218 | * @param string $userId ID or Email Address of the user. | 
| 219 | 219 | * @return bool [description] | 
| 220 | 220 | */ | 
| 221 | - public function endWatch(string $userId='me'):bool | |
| 221 | + public function endWatch(string $userId = 'me'):bool | |
| 222 | 222 |    { | 
| 223 | 223 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( | 
| 224 | - self::API . "$userId/stop", | |
| 224 | + self::API."$userId/stop", | |
| 225 | 225 | ["Authorization: Bearer $this->token"] | 
| 226 | 226 | ); | 
| 227 | 227 | $this->lastResponse = $response; | 
| @@ -236,10 +236,10 @@ discard block | ||
| 236 | 236 | * @param string $userID [description] | 
| 237 | 237 | * @return null|array [description] | 
| 238 | 238 | */ | 
| 239 | - public function getLabels(string $userId='me'):?object | |
| 239 | + public function getLabels(string $userId = 'me'): ?object | |
| 240 | 240 |    { | 
| 241 | 241 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( | 
| 242 | - self::API . "$userId/labels", | |
| 242 | + self::API."$userId/labels", | |
| 243 | 243 | ["Authorization: Bearer $this->token"] | 
| 244 | 244 | ); | 
| 245 | 245 | $this->lastResponse = $response; | 
| @@ -261,9 +261,9 @@ discard block | ||
| 261 | 261 | * @param [type] $truncateAfter [description] | 
| 262 | 262 | * @return [type] [description] | 
| 263 | 263 | */ | 
| 264 | - public function getMessages(string $userId='me', array $labelIds=null, | |
| 265 | - string $q=null, int $maxMessages=null, string $pageToken=null, bool $includeSpamTrash=false, | |
| 266 | - $truncateAfter=null):?object | |
| 264 | + public function getMessages(string $userId = 'me', array $labelIds = null, | |
| 265 | + string $q = null, int $maxMessages = null, string $pageToken = null, bool $includeSpamTrash = false, | |
| 266 | + $truncateAfter = null): ?object | |
| 267 | 267 |    { | 
| 268 | 268 | $query = []; | 
| 269 | 269 | |
| @@ -274,7 +274,7 @@ discard block | ||
| 274 | 274 | if ($maxMessages != null) $query['maxResults'] = $maxMessages; | 
| 275 | 275 | |
| 276 | 276 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( | 
| 277 | - self::API . "$userId/messages" . build_url_query($query), | |
| 277 | + self::API."$userId/messages".build_url_query($query), | |
| 278 | 278 | ["Authorization: Bearer $this->token"] | 
| 279 | 279 | ); | 
| 280 | 280 | |
| @@ -284,7 +284,7 @@ discard block | ||
| 284 | 284 |      if ($response !== false) { | 
| 285 | 285 |        if ($truncateAfter != null && $code == 200) { | 
| 286 | 286 | $response = json_decode($response); | 
| 287 | -        $response->messages = array_filter($response->messages, function ($e) use ($truncateAfter) { | |
| 287 | +        $response->messages = array_filter($response->messages, function($e) use ($truncateAfter) { | |
| 288 | 288 | return strcmp($truncateAfter, $e->id) < 0; | 
| 289 | 289 | }); | 
| 290 | 290 |          $response->{self::HTTP_CODE} = $code; | 
| @@ -305,8 +305,8 @@ discard block | ||
| 305 | 305 | * @param [type] $metadataHeaders [description] | 
| 306 | 306 | * @return Message|null [description] | 
| 307 | 307 | */ | 
| 308 | - public function getMessage(string $userId='me', string $messageId, | |
| 309 | - string $format='full', array $metadataHeaders=null):?Message | |
| 308 | + public function getMessage(string $userId = 'me', string $messageId, | |
| 309 | + string $format = 'full', array $metadataHeaders = null): ?Message | |
| 310 | 310 |    { | 
| 311 | 311 | $query = []; | 
| 312 | 312 | |
| @@ -314,7 +314,7 @@ discard block | ||
| 314 | 314 | if ($metadataHeaders != null) $query['metadataHeaders'] = $metadataHeaders; | 
| 315 | 315 | |
| 316 | 316 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( | 
| 317 | - self::API . "$userId/messages/$messageId?" . http_build_query($query), | |
| 317 | + self::API."$userId/messages/$messageId?".http_build_query($query), | |
| 318 | 318 | ["Authorization: Bearer $this->token"] | 
| 319 | 319 | ); | 
| 320 | 320 | |
| @@ -352,7 +352,7 @@ discard block | ||
| 352 | 352 | * @param string $response [description] | 
| 353 | 353 | * @return [type] [description] | 
| 354 | 354 | */ | 
| 355 | -  private function process_response(int $code, string $response):?object { | |
| 355 | +  private function process_response(int $code, string $response): ?object { | |
| 356 | 356 | $response = json_decode($response); | 
| 357 | 357 |      $response->{self::HTTP_CODE} = $code; | 
| 358 | 358 | return $response; | 
| @@ -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 | } |