| @@ -15,7 +15,7 @@ discard block | ||
| 15 | 15 | private $token; | 
| 16 | 16 | private $userAgent = 'CodeIgniter GMail API'; | 
| 17 | 17 | |
| 18 | - function __construct($params=null) | |
| 18 | + function __construct($params = null) | |
| 19 | 19 |    { | 
| 20 | 20 |      get_instance()->load->splint('francis94c/ci-gmail', '%curl'); | 
| 21 | 21 |      get_instance()->load->splint('francis94c/ci-gmail', '%base64'); | 
| @@ -23,7 +23,7 @@ discard block | ||
| 23 | 23 | if ($params != null) $this->init($params); | 
| 24 | 24 | |
| 25 | 25 |      spl_autoload_register(function($name) { | 
| 26 | - $oldPath = set_include_path(APPPATH . 'splints/' . self::PACKAGE . '/libraries'); | |
| 26 | + $oldPath = set_include_path(APPPATH.'splints/'.self::PACKAGE.'/libraries'); | |
| 27 | 27 |        require("$name.php"); | 
| 28 | 28 | set_include_path($oldPath); | 
| 29 | 29 | }); | 
| @@ -50,7 +50,7 @@ discard block | ||
| 50 | 50 | * [getClientId Get Client ID.] | 
| 51 | 51 | * @return null|string Client ID. | 
| 52 | 52 | */ | 
| 53 | -  public function getClientId():?string { | |
| 53 | +  public function getClientId(): ?string { | |
| 54 | 54 | return $this->clientId; | 
| 55 | 55 | } | 
| 56 | 56 | /** | 
| @@ -63,7 +63,7 @@ discard block | ||
| 63 | 63 | * @param bool $prompt Add the prompt=consent query to the URL. | 
| 64 | 64 | * @return string Authorize URL | 
| 65 | 65 | */ | 
| 66 | - public function getAuthorizeUrl(string $scope, string $redirectUri=null, string $responseType='code', string $accessType='offline', bool $prompt=false):string | |
| 66 | + public function getAuthorizeUrl(string $scope, string $redirectUri = null, string $responseType = 'code', string $accessType = 'offline', bool $prompt = false):string | |
| 67 | 67 |    { | 
| 68 | 68 | $redirectUri = $redirectUri ?? $this->redirectUri; | 
| 69 | 69 |      if ($scope == null) throw new Exception("GMail scope cannot be null"); | 
| @@ -75,14 +75,14 @@ discard block | ||
| 75 | 75 | 'access_type' => $accessType | 
| 76 | 76 | ]; | 
| 77 | 77 | if ($prompt) $params['prompt'] = 'consent'; | 
| 78 | - return self::AUTH_URL . build_url_query($params, false); | |
| 78 | + return self::AUTH_URL.build_url_query($params, false); | |
| 79 | 79 | } | 
| 80 | 80 | /** | 
| 81 | 81 | * [getToken description] | 
| 82 | 82 | * @param string $code [description] | 
| 83 | 83 | * @return [type] [description] | 
| 84 | 84 | */ | 
| 85 | - public function getToken(string $code, string $redirectUri=null):?array | |
| 85 | + public function getToken(string $code, string $redirectUri = null): ?array | |
| 86 | 86 |    { | 
| 87 | 87 | $redirectUri = $redirectUri ?? $this->redirectUri; | 
| 88 | 88 | $ch = curl_init(self::TOKEN_URL); | 
| @@ -100,7 +100,7 @@ discard block | ||
| 100 | 100 | ]); | 
| 101 | 101 | $header = [ | 
| 102 | 102 | 'Content-Type: application/x-www-form-urlencoded', | 
| 103 | - 'Content-Length: ' . strlen($body) | |
| 103 | + 'Content-Length: '.strlen($body) | |
| 104 | 104 | ]; | 
| 105 | 105 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | 
| 106 | 106 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); | 
| @@ -118,7 +118,7 @@ discard block | ||
| 118 | 118 | * @param string $refreshToken [description] | 
| 119 | 119 | * @return [type] [description] | 
| 120 | 120 | */ | 
| 121 | -  public function refreshAccessToken(string $refreshToken):?array { | |
| 121 | +  public function refreshAccessToken(string $refreshToken): ?array { | |
| 122 | 122 | $ch = curl_init(self::TOKEN_URL); | 
| 123 | 123 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | 
| 124 | 124 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); | 
| @@ -133,7 +133,7 @@ discard block | ||
| 133 | 133 | ]); | 
| 134 | 134 | $header = [ | 
| 135 | 135 | 'Content-Type: application/x-www-form-urlencoded', | 
| 136 | - 'Content-Length: ' . strlen($body) | |
| 136 | + 'Content-Length: '.strlen($body) | |
| 137 | 137 | ]; | 
| 138 | 138 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | 
| 139 | 139 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); | 
| @@ -153,9 +153,9 @@ discard block | ||
| 153 | 153 | * @param string $user [description] | 
| 154 | 154 | * @return [type] [description] | 
| 155 | 155 | */ | 
| 156 | -  public function getProfile(string $user='me'):?array { | |
| 156 | +  public function getProfile(string $user = 'me'): ?array { | |
| 157 | 157 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( | 
| 158 | - self::API . "$user/profile", | |
| 158 | + self::API."$user/profile", | |
| 159 | 159 | ["Authorization: Bearer $this->token"] | 
| 160 | 160 | ); | 
| 161 | 161 | if ($response !== false) return $this->process_response($code, $response); | 
| @@ -173,7 +173,7 @@ discard block | ||
| 173 | 173 | * @param string $labelFilterAction [description] | 
| 174 | 174 | * @return [type] [description] | 
| 175 | 175 | */ | 
| 176 | -  public function watch(string $topic, $labelIds=null, string $userId='me', string $labelFilterAction='include'):?array { | |
| 176 | +  public function watch(string $topic, $labelIds = null, string $userId = 'me', string $labelFilterAction = 'include'): ?array { | |
| 177 | 177 | $body = [ | 
| 178 | 178 | 'topicName' => $topic, | 
| 179 | 179 | 'labelFilterAction' => $labelFilterAction | 
| @@ -188,7 +188,7 @@ discard block | ||
| 188 | 188 | } | 
| 189 | 189 | |
| 190 | 190 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( | 
| 191 | - self::API . "$userId/watch", | |
| 191 | + self::API."$userId/watch", | |
| 192 | 192 | ["Authorization: Bearer $this->token"], | 
| 193 | 193 | $body | 
| 194 | 194 | ); | 
| @@ -201,10 +201,10 @@ discard block | ||
| 201 | 201 | * @param string $userId ID or Email Address of the user. | 
| 202 | 202 | * @return bool [description] | 
| 203 | 203 | */ | 
| 204 | - public function endWatch(string $userId='me'):bool | |
| 204 | + public function endWatch(string $userId = 'me'):bool | |
| 205 | 205 |    { | 
| 206 | 206 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( | 
| 207 | - self::API . "$userId/stop", | |
| 207 | + self::API."$userId/stop", | |
| 208 | 208 | ["Authorization: Bearer $this->token"] | 
| 209 | 209 | ); | 
| 210 | 210 | if ($response !== false) return $code == 204; | 
| @@ -216,10 +216,10 @@ discard block | ||
| 216 | 216 | * @param string $userID [description] | 
| 217 | 217 | * @return null|array [description] | 
| 218 | 218 | */ | 
| 219 | - public function getLabels(string $userId='me'):?array | |
| 219 | + public function getLabels(string $userId = 'me'): ?array | |
| 220 | 220 |    { | 
| 221 | 221 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( | 
| 222 | - self::API . "$userId/labels", | |
| 222 | + self::API."$userId/labels", | |
| 223 | 223 | ["Authorization: Bearer $this->token"] | 
| 224 | 224 | ); | 
| 225 | 225 |      if ($response !== false) { | 
| @@ -239,9 +239,9 @@ discard block | ||
| 239 | 239 | * @param [type] $truncateAfter [description] | 
| 240 | 240 | * @return [type] [description] | 
| 241 | 241 | */ | 
| 242 | - public function getMessages(string $userId='me', array $labelIds=null, | |
| 243 | - string $q=null, int $maxMessages=null, string $pageToken=null, bool $includeSpamTrash=false, | |
| 244 | - $truncateAfter=null):?object | |
| 242 | + public function getMessages(string $userId = 'me', array $labelIds = null, | |
| 243 | + string $q = null, int $maxMessages = null, string $pageToken = null, bool $includeSpamTrash = false, | |
| 244 | + $truncateAfter = null): ?object | |
| 245 | 245 |    { | 
| 246 | 246 | $query = []; | 
| 247 | 247 | |
| @@ -252,14 +252,14 @@ discard block | ||
| 252 | 252 | if ($maxMessages != null) $query['maxResults'] = $maxMessages; | 
| 253 | 253 | |
| 254 | 254 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( | 
| 255 | - self::API . "$userId/messages?" . http_build_query($query), | |
| 255 | + self::API."$userId/messages?".http_build_query($query), | |
| 256 | 256 | ["Authorization: Bearer $this->token"] | 
| 257 | 257 | ); | 
| 258 | 258 | |
| 259 | 259 |      if ($response !== false) { | 
| 260 | 260 |        if ($truncateAfter != null && $code == 200) { | 
| 261 | 261 | $response = json_decode($response); | 
| 262 | -        $response->messages = array_filter($response->messages, function ($e) use ($truncateAfter) { | |
| 262 | +        $response->messages = array_filter($response->messages, function($e) use ($truncateAfter) { | |
| 263 | 263 | return strcmp($truncateAfter, $e->id) <= 0; | 
| 264 | 264 | }); | 
| 265 | 265 |          $response->{self::HTTP_CODE} = $code; | 
| @@ -280,8 +280,8 @@ discard block | ||
| 280 | 280 | * @param [type] $metadataHeaders [description] | 
| 281 | 281 | * @return Message|null [description] | 
| 282 | 282 | */ | 
| 283 | - public function getMessage(string $userId='me', string $messageId, | |
| 284 | - string $format='full', array $metadataHeaders=null):?Message | |
| 283 | + public function getMessage(string $userId = 'me', string $messageId, | |
| 284 | + string $format = 'full', array $metadataHeaders = null): ?Message | |
| 285 | 285 |    { | 
| 286 | 286 | $query = []; | 
| 287 | 287 | |
| @@ -289,7 +289,7 @@ discard block | ||
| 289 | 289 | if ($metadataHeaders != null) $query['metadataHeaders'] = $metadataHeaders; | 
| 290 | 290 | |
| 291 | 291 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( | 
| 292 | - self::API . "$userId/messages/$messageId?" . http_build_query($query), | |
| 292 | + self::API."$userId/messages/$messageId?".http_build_query($query), | |
| 293 | 293 | ["Authorization: Bearer $this->token"] | 
| 294 | 294 | ); | 
| 295 | 295 | |
| @@ -20,7 +20,9 @@ discard block | ||
| 20 | 20 |      get_instance()->load->splint('francis94c/ci-gmail', '%curl'); | 
| 21 | 21 |      get_instance()->load->splint('francis94c/ci-gmail', '%base64'); | 
| 22 | 22 | |
| 23 | - if ($params != null) $this->init($params); | |
| 23 | +    if ($params != null) { | |
| 24 | + $this->init($params); | |
| 25 | + } | |
| 24 | 26 | |
| 25 | 27 |      spl_autoload_register(function($name) { | 
| 26 | 28 | $oldPath = set_include_path(APPPATH . 'splints/' . self::PACKAGE . '/libraries'); | 
| @@ -66,7 +68,9 @@ discard block | ||
| 66 | 68 | public function getAuthorizeUrl(string $scope, string $redirectUri=null, string $responseType='code', string $accessType='offline', bool $prompt=false):string | 
| 67 | 69 |    { | 
| 68 | 70 | $redirectUri = $redirectUri ?? $this->redirectUri; | 
| 69 | -    if ($scope == null) throw new Exception("GMail scope cannot be null"); | |
| 71 | +    if ($scope == null) { | |
| 72 | +      throw new Exception("GMail scope cannot be null"); | |
| 73 | + } | |
| 70 | 74 | $params = [ | 
| 71 | 75 | 'client_id' => $this->clientId, | 
| 72 | 76 | 'redirect_uri' => $redirectUri, | 
| @@ -74,7 +78,9 @@ discard block | ||
| 74 | 78 | 'response_type' => $responseType, | 
| 75 | 79 | 'access_type' => $accessType | 
| 76 | 80 | ]; | 
| 77 | - if ($prompt) $params['prompt'] = 'consent'; | |
| 81 | +    if ($prompt) { | |
| 82 | + $params['prompt'] = 'consent'; | |
| 83 | + } | |
| 78 | 84 | return self::AUTH_URL . build_url_query($params, false); | 
| 79 | 85 | } | 
| 80 | 86 | /** | 
| @@ -110,7 +116,9 @@ discard block | ||
| 110 | 116 | $response = curl_exec($ch); | 
| 111 | 117 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | 
| 112 | 118 | curl_close($ch); | 
| 113 | - if ($response !== false) return $this->process_response($code, $response); | |
| 119 | +    if ($response !== false) { | |
| 120 | + return $this->process_response($code, $response); | |
| 121 | + } | |
| 114 | 122 | return null; | 
| 115 | 123 | } | 
| 116 | 124 | /** | 
| @@ -144,7 +152,9 @@ discard block | ||
| 144 | 152 | $response = curl_exec($ch); | 
| 145 | 153 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | 
| 146 | 154 | curl_close($ch); | 
| 147 | - if ($response !== false) return $this->process_response($code, $response); | |
| 155 | +    if ($response !== false) { | |
| 156 | + return $this->process_response($code, $response); | |
| 157 | + } | |
| 148 | 158 | return null; | 
| 149 | 159 | } | 
| 150 | 160 | /** | 
| @@ -158,7 +168,9 @@ discard block | ||
| 158 | 168 | self::API . "$user/profile", | 
| 159 | 169 | ["Authorization: Bearer $this->token"] | 
| 160 | 170 | ); | 
| 161 | - if ($response !== false) return $this->process_response($code, $response); | |
| 171 | +    if ($response !== false) { | |
| 172 | + return $this->process_response($code, $response); | |
| 173 | + } | |
| 162 | 174 | return null; | 
| 163 | 175 | } | 
| 164 | 176 | /** | 
| @@ -192,7 +204,9 @@ discard block | ||
| 192 | 204 | ["Authorization: Bearer $this->token"], | 
| 193 | 205 | $body | 
| 194 | 206 | ); | 
| 195 | - if ($response !== false) return $this->process_response($code, $response); | |
| 207 | +    if ($response !== false) { | |
| 208 | + return $this->process_response($code, $response); | |
| 209 | + } | |
| 196 | 210 | return null; | 
| 197 | 211 | } | 
| 198 | 212 | /** | 
| @@ -207,7 +221,9 @@ discard block | ||
| 207 | 221 | self::API . "$userId/stop", | 
| 208 | 222 | ["Authorization: Bearer $this->token"] | 
| 209 | 223 | ); | 
| 210 | - if ($response !== false) return $code == 204; | |
| 224 | +    if ($response !== false) { | |
| 225 | + return $code == 204; | |
| 226 | + } | |
| 211 | 227 | return false; | 
| 212 | 228 | } | 
| 213 | 229 | /** | 
| @@ -245,11 +261,21 @@ discard block | ||
| 245 | 261 |    { | 
| 246 | 262 | $query = []; | 
| 247 | 263 | |
| 248 | - if ($labelIds != null) $query['labelIds'] = $labelIds; | |
| 249 | - if ($includeSpamTrash) $query['includeSpamTrash'] = $includeSpamTrash; | |
| 250 | - if ($q != null) $query['q'] = $q; | |
| 251 | - if ($pageToken != null) $query['pageToken'] = $pageToken; | |
| 252 | - if ($maxMessages != null) $query['maxResults'] = $maxMessages; | |
| 264 | +    if ($labelIds != null) { | |
| 265 | + $query['labelIds'] = $labelIds; | |
| 266 | + } | |
| 267 | +    if ($includeSpamTrash) { | |
| 268 | + $query['includeSpamTrash'] = $includeSpamTrash; | |
| 269 | + } | |
| 270 | +    if ($q != null) { | |
| 271 | + $query['q'] = $q; | |
| 272 | + } | |
| 273 | +    if ($pageToken != null) { | |
| 274 | + $query['pageToken'] = $pageToken; | |
| 275 | + } | |
| 276 | +    if ($maxMessages != null) { | |
| 277 | + $query['maxResults'] = $maxMessages; | |
| 278 | + } | |
| 253 | 279 | |
| 254 | 280 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( | 
| 255 | 281 | self::API . "$userId/messages?" . http_build_query($query), | 
| @@ -285,15 +311,21 @@ discard block | ||
| 285 | 311 |    { | 
| 286 | 312 | $query = []; | 
| 287 | 313 | |
| 288 | - if ($format != 'full' && $format != null) $query['format'] = $format; | |
| 289 | - if ($metadataHeaders != null) $query['metadataHeaders'] = $metadataHeaders; | |
| 314 | +    if ($format != 'full' && $format != null) { | |
| 315 | + $query['format'] = $format; | |
| 316 | + } | |
| 317 | +    if ($metadataHeaders != null) { | |
| 318 | + $query['metadataHeaders'] = $metadataHeaders; | |
| 319 | + } | |
| 290 | 320 | |
| 291 | 321 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( | 
| 292 | 322 | self::API . "$userId/messages/$messageId?" . http_build_query($query), | 
| 293 | 323 | ["Authorization: Bearer $this->token"] | 
| 294 | 324 | ); | 
| 295 | 325 | |
| 296 | - if ($response !== false) return new Message($response); | |
| 326 | +    if ($response !== false) { | |
| 327 | + return new Message($response); | |
| 328 | + } | |
| 297 | 329 | |
| 298 | 330 | return null; | 
| 299 | 331 | } |