@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | private $token; |
18 | 18 | private $userAgent = 'CodeIgniter GMail API'; |
19 | 19 | |
20 | - function __construct($params=null) { |
|
20 | + function __construct($params = null) { |
|
21 | 21 | get_instance()->load->splint('francis94c/ci-gmail', '%curl'); |
22 | 22 | if ($params != null) $this->init($params); |
23 | 23 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * [getClientId Get Client ID.] |
44 | 44 | * @return null|string Client ID. |
45 | 45 | */ |
46 | - public function getClientId():?string { |
|
46 | + public function getClientId(): ?string { |
|
47 | 47 | return $this->clientId; |
48 | 48 | } |
49 | 49 | /** |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @param bool $prompt Add the prompt=consent query to the URL. |
57 | 57 | * @return string Authorize URL |
58 | 58 | */ |
59 | - public function getAuthorizeUrl(string $scope, string $redirectUri=null, string $responseType='code', string $accessType='offline', bool $prompt=false):string |
|
59 | + public function getAuthorizeUrl(string $scope, string $redirectUri = null, string $responseType = 'code', string $accessType = 'offline', bool $prompt = false):string |
|
60 | 60 | { |
61 | 61 | $redirectUri = $redirectUri ?? $this->redirectUri; |
62 | 62 | if ($scope == null) throw new Exception("GMail scope cannot be null"); |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | 'access_type' => $accessType |
69 | 69 | ]; |
70 | 70 | if ($prompt) $params['prompt'] = 'consent'; |
71 | - return self::AUTH_URL . build_url_query($params, false); |
|
71 | + return self::AUTH_URL.build_url_query($params, false); |
|
72 | 72 | } |
73 | 73 | /** |
74 | 74 | * [getToken description] |
75 | 75 | * @param string $code [description] |
76 | 76 | * @return [type] [description] |
77 | 77 | */ |
78 | - public function getToken(string $code, string $redirectUri=null):?array |
|
78 | + public function getToken(string $code, string $redirectUri = null): ?array |
|
79 | 79 | { |
80 | 80 | $redirectUri = $redirectUri ?? $this->redirectUri; |
81 | 81 | $ch = curl_init(self::TOKEN_URL); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | ]); |
94 | 94 | $header = [ |
95 | 95 | 'Content-Type: application/x-www-form-urlencoded', |
96 | - 'Content-Length: ' . strlen($body) |
|
96 | + 'Content-Length: '.strlen($body) |
|
97 | 97 | ]; |
98 | 98 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
99 | 99 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @param string $refreshToken [description] |
112 | 112 | * @return [type] [description] |
113 | 113 | */ |
114 | - public function refreshAccessToken(string $refreshToken):?array { |
|
114 | + public function refreshAccessToken(string $refreshToken): ?array { |
|
115 | 115 | $ch = curl_init(self::TOKEN_URL); |
116 | 116 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
117 | 117 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | ]); |
127 | 127 | $header = [ |
128 | 128 | 'Content-Type: application/x-www-form-urlencoded', |
129 | - 'Content-Length: ' . strlen($body) |
|
129 | + 'Content-Length: '.strlen($body) |
|
130 | 130 | ]; |
131 | 131 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
132 | 132 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | * @param string $user [description] |
147 | 147 | * @return [type] [description] |
148 | 148 | */ |
149 | - public function getProfile(string $user='me'):?array { |
|
149 | + public function getProfile(string $user = 'me'): ?array { |
|
150 | 150 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
151 | - self::API . "$user/profile", |
|
151 | + self::API."$user/profile", |
|
152 | 152 | ["Authorization: Bearer $this->token"] |
153 | 153 | ); |
154 | 154 | if ($response !== false) return $this->process_response($code, $response); |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @param string $labelFilterAction [description] |
167 | 167 | * @return [type] [description] |
168 | 168 | */ |
169 | - public function watch(string $topic, $labelIds=null, string $userId='me', string $labelFilterAction='include'):?array { |
|
169 | + public function watch(string $topic, $labelIds = null, string $userId = 'me', string $labelFilterAction = 'include'): ?array { |
|
170 | 170 | $body = [ |
171 | 171 | 'topicName' => $topic, |
172 | 172 | 'labelFilterAction' => $labelFilterAction |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( |
184 | - self::API . "$userId/watch", |
|
184 | + self::API."$userId/watch", |
|
185 | 185 | ["Authorization: Bearer $this->token"], |
186 | 186 | $body |
187 | 187 | ); |
@@ -194,10 +194,10 @@ discard block |
||
194 | 194 | * @param string $userId ID or Email Address of the user. |
195 | 195 | * @return bool [description] |
196 | 196 | */ |
197 | - public function endWatch(string $userId='me'):bool |
|
197 | + public function endWatch(string $userId = 'me'):bool |
|
198 | 198 | { |
199 | 199 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( |
200 | - self::API . "$userId/stop", |
|
200 | + self::API."$userId/stop", |
|
201 | 201 | ["Authorization: Bearer $this->token"] |
202 | 202 | ); |
203 | 203 | if ($response !== false) return $code == 204; |
@@ -209,10 +209,10 @@ discard block |
||
209 | 209 | * @param string $userID [description] |
210 | 210 | * @return null|array [description] |
211 | 211 | */ |
212 | - public function getLabels(string $userId='me'):?array |
|
212 | + public function getLabels(string $userId = 'me'): ?array |
|
213 | 213 | { |
214 | 214 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
215 | - self::API . "$userId/labels", |
|
215 | + self::API."$userId/labels", |
|
216 | 216 | ["Authorization: Bearer $this->token"] |
217 | 217 | ); |
218 | 218 | if ($response !== false) { |
@@ -232,9 +232,9 @@ discard block |
||
232 | 232 | * @param [type] $truncateAfter [description] |
233 | 233 | * @return [type] [description] |
234 | 234 | */ |
235 | - public function getEmails(string $userId='me', array $labelIds=null, |
|
236 | - string $q=null, int $maxEmails=null, string $pageToken=null, bool $includeSpamTrash=false, |
|
237 | - $truncateAfter=null):?object |
|
235 | + public function getEmails(string $userId = 'me', array $labelIds = null, |
|
236 | + string $q = null, int $maxEmails = null, string $pageToken = null, bool $includeSpamTrash = false, |
|
237 | + $truncateAfter = null): ?object |
|
238 | 238 | { |
239 | 239 | $query = []; |
240 | 240 | |
@@ -245,14 +245,14 @@ discard block |
||
245 | 245 | if ($maxEmails != null) $query['maxResults'] = $maxEmails; |
246 | 246 | |
247 | 247 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
248 | - self::API . "$userId/messages?" . http_build_query($query), |
|
248 | + self::API."$userId/messages?".http_build_query($query), |
|
249 | 249 | ["Authorization: Bearer $this->token"] |
250 | 250 | ); |
251 | 251 | |
252 | 252 | if ($response !== false) { |
253 | 253 | if ($truncateAfter != null && $code == 200) { |
254 | 254 | $response = json_decode($response); |
255 | - $response->messages = array_filter($response->messages, function ($e) use ($truncateAfter) { |
|
255 | + $response->messages = array_filter($response->messages, function($e) use ($truncateAfter) { |
|
256 | 256 | return strcmp($truncateAfter, $e->id) <= 0; |
257 | 257 | }); |
258 | 258 | $response->{self::HTTP_CODE} = $code; |