11<?php
22
3+ declare (strict_types=1 );
4+
35namespace Dacastro4 \LaravelGmail ;
46
57use Dacastro4 \LaravelGmail \Traits \Configurable ;
@@ -17,21 +19,21 @@ class GmailConnection extends Google_Client
1719 }
1820 use HasLabels;
1921
20- protected $ emailAddress ;
22+ protected ? string $ emailAddress = null ;
2123
22- protected $ refreshToken ;
24+ protected ? string $ refreshToken = null ;
2325
24- protected $ app ;
26+ protected Container $ app ;
2527
26- protected $ accessToken ;
28+ protected mixed $ accessToken = null ;
2729
28- protected $ token ;
30+ protected mixed $ token = null ;
2931
30- private $ configuration ;
32+ private mixed $ configuration ;
3133
32- protected ? int $ userId = null ;
34+ public ? string $ userId = null ;
3335
34- public function __construct ($ config = null , $ userId = null )
36+ public function __construct (mixed $ config = null , ? string $ userId = null )
3537 {
3638 $ this ->app = Container::getInstance ();
3739
@@ -51,7 +53,7 @@ public function __construct($config = null, $userId = null)
5153
5254 }
5355
54- public function getUserId ()
56+ public function getUserId (): ? string
5557 {
5658 return $ this ->userId ;
5759 }
@@ -61,7 +63,7 @@ public function getUserId()
6163 *
6264 * @return bool
6365 */
64- public function checkPreviouslyLoggedIn ()
66+ public function checkPreviouslyLoggedIn (): bool
6567 {
6668 $ fileName = $ this ->getFileName ();
6769 $ file = "gmail/tokens/ $ fileName.json " ;
@@ -83,7 +85,7 @@ public function checkPreviouslyLoggedIn()
8385 *
8486 * @return mixed|null
8587 */
86- private function refreshTokenIfNeeded ()
88+ private function refreshTokenIfNeeded (): mixed
8789 {
8890 if ($ this ->isAccessTokenExpired ()) {
8991 $ this ->fetchAccessTokenWithRefreshToken ($ this ->getRefreshToken ());
@@ -103,7 +105,7 @@ private function refreshTokenIfNeeded()
103105 *
104106 * @return bool Returns True if the access_token is expired.
105107 */
106- public function isAccessTokenExpired ()
108+ public function isAccessTokenExpired (): bool
107109 {
108110 $ token = $ this ->getToken ();
109111
@@ -114,17 +116,17 @@ public function isAccessTokenExpired()
114116 return parent ::isAccessTokenExpired ();
115117 }
116118
117- public function getToken ()
119+ public function getToken (): mixed
118120 {
119121 return parent ::getAccessToken () ?: $ this ->config ();
120122 }
121123
122- public function setToken ($ token )
124+ public function setToken (mixed $ token ): void
123125 {
124126 $ this ->setAccessToken ($ token );
125127 }
126128
127- public function getAccessToken ()
129+ public function getAccessToken (): mixed
128130 {
129131 $ token = parent ::getAccessToken () ?: $ this ->config ();
130132
@@ -139,7 +141,7 @@ public function setAccessToken($token)
139141 parent ::setAccessToken ($ token );
140142 }
141143
142- public function setBothAccessToken ($ token )
144+ public function setBothAccessToken (array | string $ token ): void
143145 {
144146 $ this ->setAccessToken ($ token );
145147 $ this ->saveAccessToken ($ token );
@@ -148,7 +150,7 @@ public function setBothAccessToken($token)
148150 /**
149151 * Save the credentials in a file
150152 */
151- public function saveAccessToken (array $ config )
153+ public function saveAccessToken (array $ config ): void
152154 {
153155 $ disk = Storage::disk ('local ' );
154156 $ fileName = $ this ->getFileName ();
@@ -185,7 +187,7 @@ public function saveAccessToken(array $config)
185187 *
186188 * @throws \Exception
187189 */
188- public function makeToken (Request $ request )
190+ public function makeToken (Request $ request ): array | string
189191 {
190192 if (! $ this ->check ()) {
191193 $ code = (string ) $ request ->input ('code ' , null );
@@ -214,7 +216,7 @@ public function makeToken(Request $request)
214216 *
215217 * @return bool
216218 */
217- public function check ()
219+ public function check (): bool
218220 {
219221 return ! $ this ->isAccessTokenExpired ();
220222 }
@@ -224,7 +226,7 @@ public function check()
224226 *
225227 * @return \Google_Service_Gmail_Profile
226228 */
227- public function getProfile ()
229+ public function getProfile (): \ Google_Service_Gmail_Profile
228230 {
229231 $ service = new Google_Service_Gmail ($ this );
230232
@@ -234,15 +236,15 @@ public function getProfile()
234236 /**
235237 * Revokes user's permission and logs them out
236238 */
237- public function logout ()
239+ public function logout (): void
238240 {
239241 $ this ->revokeToken ();
240242 }
241243
242244 /**
243245 * Delete the credentials in a file
244246 */
245- public function deleteAccessToken ()
247+ public function deleteAccessToken (): void
246248 {
247249 $ disk = Storage::disk ('local ' );
248250 $ fileName = $ this ->getFileName ();
@@ -262,7 +264,7 @@ public function deleteAccessToken()
262264
263265 }
264266
265- private function haveReadScope ()
267+ private function haveReadScope (): bool
266268 {
267269 $ scopes = $ this ->getUserScopes ();
268270
@@ -276,7 +278,7 @@ private function haveReadScope()
276278 * @param array $optParams
277279 * @return \Google_Service_Gmail_Stop
278280 */
279- public function stopWatch ($ userEmail , $ optParams = [])
281+ public function stopWatch (string $ userEmail , array $ optParams = []): \ Google_Service_Gmail_Stop
280282 {
281283 $ service = new Google_Service_Gmail ($ this );
282284
@@ -288,7 +290,7 @@ public function stopWatch($userEmail, $optParams = [])
288290 *
289291 * @param string $userEmail Email address
290292 */
291- public function setWatch ($ userEmail , \Google_Service_Gmail_WatchRequest $ postData ): \Google_Service_Gmail_WatchResponse
293+ public function setWatch (string $ userEmail , \Google_Service_Gmail_WatchRequest $ postData ): \Google_Service_Gmail_WatchResponse
292294 {
293295 $ service = new Google_Service_Gmail ($ this );
294296
@@ -300,7 +302,7 @@ public function setWatch($userEmail, \Google_Service_Gmail_WatchRequest $postDat
300302 *
301303 * @return \Google\Service\Gmail\ListHistoryResponse
302304 */
303- public function historyList ($ userEmail , $ params )
305+ public function historyList (string $ userEmail , array $ params ): \ Google \ Service \ Gmail \ ListHistoryResponse
304306 {
305307 $ service = new Google_Service_Gmail ($ this );
306308
0 commit comments