Skip to content

Commit 9643af5

Browse files
committed
feat: add strict typing across source
1 parent 6e1aba0 commit 9643af5

19 files changed

+252
-559
lines changed

src/Exceptions/AuthException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Dacastro4\LaravelGmail\Exceptions;
46

57
class AuthException extends \Exception {}

src/Facade/LaravelGmail.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Dacastro4\LaravelGmail\Facade;
46

57
use Illuminate\Support\Facades\Facade;
68

79
class LaravelGmail extends Facade
810
{
9-
protected static function getFacadeAccessor()
11+
protected static function getFacadeAccessor(): string
1012
{
1113
return 'laravelgmail';
1214
}

src/GmailConnection.php

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Dacastro4\LaravelGmail;
46

57
use 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

src/LaravelGmailClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class LaravelGmailClass extends GmailConnection
1313
{
14-
public function __construct($config, $userId = null)
14+
public function __construct(mixed $config, ?string $userId = null)
1515
{
1616
if (class_basename($config) === 'Application') {
1717
$config = $config['config'];
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Dacastro4\LaravelGmail;
46

57
use Illuminate\Support\Facades\App;
68
use Illuminate\Support\ServiceProvider;
79

810
class LaravelGmailServiceProvider extends ServiceProvider
911
{
10-
public function boot()
12+
public function boot(): void
1113
{
1214
$this->publishes([__DIR__.'/config/gmail.php' => App::make('path.config').'/gmail.php']);
1315
}
1416

15-
public function register()
17+
public function register(): void
1618
{
17-
1819
$this->mergeConfigFrom(__DIR__.'/config/gmail.php', 'gmail');
1920

2021
// Main Service
21-
$this->app->bind('laravelgmail', function ($app) {
22+
$this->app->bind('laravelgmail', function ($app): LaravelGmailClass {
2223
return new LaravelGmailClass($app['config']);
2324
});
24-
2525
}
2626
}

src/Services/Message.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Dacastro4\LaravelGmail\Services;
46

57
use Dacastro4\LaravelGmail\LaravelGmailClass;
@@ -16,7 +18,7 @@ class Message
1618
use Filterable,
1719
SendsParameters;
1820

19-
private Google_Service_Gmail $service;
21+
public mixed $service;
2022

2123
private bool $preload = false;
2224

@@ -160,7 +162,7 @@ private function getRequest(string $id): Google_Service_Gmail_Message
160162
/**
161163
* @throws \Google_Exception
162164
*/
163-
private function getMessagesResponse(): array|Google_Service_Gmail_ListMessagesResponse
165+
private function getMessagesResponse(): mixed
164166
{
165167
$responseOrRequest = $this->service->users_messages->listUsersMessages('me', $this->params);
166168

0 commit comments

Comments
 (0)