@@ -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 != 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; |