Skip to content

Commit b576096

Browse files
committed
:octocat: enable phan for tests & examples, phan happy
1 parent e7a722f commit b576096

14 files changed

+37
-21
lines changed

.phan/config.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
// Thus, both first-party and third-party code being used by
2626
// your application should be included in this list.
2727
'directory_list' => [
28+
'examples',
2829
'src',
2930
'tests',
3031
'vendor',
@@ -48,7 +49,9 @@
4849
// should be added to both the `directory_list`
4950
// and `exclude_analysis_directory_list` arrays.
5051
'exclude_analysis_directory_list' => [
51-
'tests',
5252
'vendor',
5353
],
54+
'suppress_issue_types' => [
55+
'PhanUndeclaredGlobalVariable', // happens in get-token examples
56+
],
5457
];

examples/get-token/_flow-oauth1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
if($provider instanceof UserInfo){
4242
printf('<pre>%s</pre>', print_r($provider->me(), true));
4343
}
44-
44+
/** @phan-suppress-next-line PhanUndeclaredMethod ($provider is, in fact, also instance of OAuthInterface) */
4545
$tokenJSON = $provider->getAccessTokenFromStorage()->toJSON();
4646

4747
printf('<textarea cols="120" rows="5" onclick="this.select();">%s</textarea>', $tokenJSON);

examples/get-token/_flow-oauth2.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
if($provider instanceof CSRFToken && isset($_GET['state'])){
3232
$state = $_GET['state'];
3333
}
34-
34+
/** @phan-suppress-next-line PhanUndeclaredMethod ($provider is, in fact, also instance of OAuthInterface) */
3535
$token = $provider->getAccessToken($_GET['code'], $state);
3636

3737
// save the token [...]
@@ -48,7 +48,7 @@
4848
if($provider instanceof UserInfo){
4949
printf('<pre>%s</pre>', print_r($provider->me(), true));
5050
}
51-
51+
/** @phan-suppress-next-line PhanUndeclaredMethod */
5252
$tokenJSON = $provider->getAccessTokenFromStorage()->toJSON();
5353

5454
printf('<textarea cols="120" rows="5" onclick="this.select();">%s</textarea>', $tokenJSON);

src/Core/AccessToken.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-1.4
2323
*
2424
* // Oauth1
25-
* @property string|null $accessTokenSecret
25+
* @property string|null $accessTokenSecret
2626
*
2727
* // Oauth2
28-
* @property array $scopes
29-
* @property string|null $refreshToken
28+
* @property array $scopes
29+
* @property string|null $refreshToken
3030
*
3131
* // common
32-
* @property string|null $accessToken
33-
* @property int $expires
34-
* @property array $extraParams
35-
* @property string $provider
32+
* @property string|null $accessToken
33+
* @property DateTime|DateInterval|int|null $expires
34+
* @property array $extraParams
35+
* @property string $provider
3636
*/
3737
final class AccessToken extends SettingsContainerAbstract{
3838

tests/Core/OAuthOptionsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testSetStorageEncryptionKey():void{
3131
public function testSetStorageEncryptionKeyInvalidException():void{
3232
$this->expectException(OAuthStorageException::class);
3333
$this->expectExceptionMessage('invalid encryption key');
34-
34+
/** @phan-suppress-next-line PhanNoopNew */
3535
new OAuthOptions(['storageEncryptionKey' => 'foo']);
3636
}
3737

@@ -44,7 +44,7 @@ public function testSetFileStoragePath():void{
4444
public function testSetFileStoragePathInvalidException():void{
4545
$this->expectException(OAuthStorageException::class);
4646
$this->expectExceptionMessage('invalid storage path "/foo"');
47-
47+
/** @phan-suppress-next-line PhanNoopNew */
4848
new OAuthOptions(['fileStoragePath' => '/foo']);
4949
}
5050

tests/Providers/DummyOAuth1Provider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace chillerlan\OAuthTest\Providers;
1313

1414
use chillerlan\OAuth\Core\{AccessToken, OAuth1Provider, TokenInvalidate};
15-
use chillerlan\OAuth\Providers\ProviderException;
1615

1716
/**
1817
* An OAuth1 provider implementation

tests/Providers/Live/OAuth2ProviderLiveTestAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testRequestCredentialsToken():void{
3030
}
3131

3232
$this->provider->setStorage(new MemoryStorage);
33-
33+
/** @phan-suppress-next-line PhanUndeclaredMethod ($this->provider is, in fact, instance of ClientCredentials) */
3434
$token = $this->provider->getClientCredentialsToken($this->clientCredentialsScopes);
3535

3636
$this::assertInstanceOf(AccessToken::class, $token);

tests/Providers/Live/OAuthProviderLiveTestAbstract.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ public function testMe():void{
3939
}
4040

4141
try{
42+
/** @phan-suppress-next-line PhanUndeclaredMethod ($this->provider is, in fact, instance of UserInfo) */
4243
$user = $this->provider->me();
4344
}
4445
catch(UnauthorizedAccessException){
4546
$this::markTestSkipped('unauthorized: token is missing or expired');
4647
}
4748

4849
try{
50+
/** @phan-suppress-next-line PhanPossiblyUndeclaredVariable */
4951
$this->assertMeResponse($user);
5052
}
5153
catch(ExpectationFailedException $e){
@@ -62,10 +64,16 @@ public function testMe():void{
6264
protected function assertUnauthorizedAccessException(AccessToken $token):void{
6365
$this->expectException(UnauthorizedAccessException::class);
6466

67+
/** @phan-suppress-next-line PhanUndeclaredMethod ($this->provider is, in fact, instance of UserInfo) */
6568
$this->provider->me();
6669
}
6770

6871
public function testUnauthorizedAccessException():void{
72+
73+
if(!$this->provider instanceof UserInfo){
74+
$this::markTestSkipped('AuthenticatedUser N/A');
75+
}
76+
6977
$token = $this->storage->getAccessToken($this->provider->name);
7078
// avoid refresh
7179
$token->expires = AccessToken::NEVER_EXPIRES;

tests/Providers/Live/PayPalAPITest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use chillerlan\OAuth\Core\AuthenticatedUser;
1515
use chillerlan\OAuth\Providers\PayPal;
1616
use PHPUnit\Framework\Attributes\Group;
17-
use function is_array;
1817

1918
/**
2019
* @property \chillerlan\OAuth\Providers\PayPal $provider

tests/Providers/Unit/OAuth1ProviderUnitTestAbstract.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* @author smiley <smiley@chillerlan.net>
77
* @copyright 2018 smiley
88
* @license MIT
9+
*
10+
* @phan-file-suppress PhanAccessMethodInternal
911
*/
1012
declare(strict_types=1);
1113

0 commit comments

Comments
 (0)