| @@ -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'):?array | |
| 239 | + public function getLabels(string $userId = 'me'): ?array | |
| 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) $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 | |
| @@ -285,7 +285,7 @@ discard block | ||
| 285 | 285 |        if ($truncateAfter != null && $code == 200) {
 | 
| 286 | 286 | $response = json_decode($response); | 
| 287 | 287 |          if ($response->messages) {
 | 
| 288 | -          $response->messages = array_filter($response->messages, function ($e) use ($truncateAfter) {
 | |
| 288 | +          $response->messages = array_filter($response->messages, function($e) use ($truncateAfter) {
 | |
| 289 | 289 | return strcmp($truncateAfter, $e->id) < 0; | 
| 290 | 290 | }); | 
| 291 | 291 | } | 
| @@ -304,7 +304,7 @@ discard block | ||
| 304 | 304 | * @date 2020-03-08 | 
| 305 | 305 | * @return string|null [description] | 
| 306 | 306 | */ | 
| 307 | - public function getLastMessageId():?string | |
| 307 | + public function getLastMessageId(): ?string | |
| 308 | 308 |    {
 | 
| 309 | 309 | $messages = $this->getMessages(); | 
| 310 | 310 | return $messages->messages[0]->id ?? null; | 
| @@ -319,8 +319,8 @@ discard block | ||
| 319 | 319 | * @param [type] $metadataHeaders [description] | 
| 320 | 320 | * @return Message|null [description] | 
| 321 | 321 | */ | 
| 322 | - public function getMessage(string $userId='me', string $messageId, | |
| 323 | - string $format='full', array $metadataHeaders=null):?Message | |
| 322 | + public function getMessage(string $userId = 'me', string $messageId, | |
| 323 | + string $format = 'full', array $metadataHeaders = null): ?Message | |
| 324 | 324 |    {
 | 
| 325 | 325 | $query = []; | 
| 326 | 326 | |
| @@ -328,7 +328,7 @@ discard block | ||
| 328 | 328 | if ($metadataHeaders != null) $query['metadataHeaders'] = $metadataHeaders; | 
| 329 | 329 | |
| 330 | 330 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( | 
| 331 | - self::API . "$userId/messages/$messageId?" . http_build_query($query), | |
| 331 | + self::API."$userId/messages/$messageId?".http_build_query($query), | |
| 332 | 332 | ["Authorization: Bearer $this->token"] | 
| 333 | 333 | ); | 
| 334 | 334 | |
| @@ -366,7 +366,7 @@ discard block | ||
| 366 | 366 | * @param string $response [description] | 
| 367 | 367 | * @return [type] [description] | 
| 368 | 368 | */ | 
| 369 | -  private function process_response(int $code, string $response):?object {
 | |
| 369 | +  private function process_response(int $code, string $response): ?object {
 | |
| 370 | 370 | $response = json_decode($response); | 
| 371 | 371 |      $response->{self::HTTP_CODE} = $code;
 | 
| 372 | 372 | return $response; |