Skip to content

Commit d1040b0

Browse files
committed
🚿 PHPCS & PHPMD happy
1 parent 961e1a6 commit d1040b0

15 files changed

+29
-15
lines changed

.idea/inspectionProfiles/Project_Default.xml

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/Providers/LastFM/topalbum-patchwork.php

-1
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,3 @@ function sendResponse(array $response):void{
152152
echo json_encode($response, JSON_PRETTY_PRINT);
153153
exit;
154154
}
155-

examples/Providers/Spotify/playlist-diff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function diff(string $playlistID1, string $playlistID2, bool $createAsPla
2929
return $diff;
3030
}
3131

32-
};
32+
}
3333

3434
/**
3535
* @var \OAuthExampleProviderFactory $factory

examples/create-description.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
$table[] = '| ['.$provider->getName().']('.$provider->getApiDocURL().')'.
4747
' | [link]('.$provider->getApplicationURL().')'.
48-
' | '.($provider->getUserRevokeURL() !== null ? '[link]('.$provider->getUserRevokeURL().')' : '').
48+
' | '.(($provider->getUserRevokeURL() !== null) ? '[link]('.$provider->getUserRevokeURL().')' : '').
4949
' | '.$oauthVersion.
5050
' | '.(($provider instanceof UserInfo) ? '' : '').
5151
' | '.(($provider instanceof CSRFToken) ? '' : '').

examples/provider-example-common.php

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
* @var string $AUTOLOADER - path to an alternate autoloader
1818
*/
19+
// PHPCS:ignore
1920
require_once ($AUTOLOADER ?? __DIR__.'/../vendor/autoload.php');
2021
require_once __DIR__.'/OAuthExampleProviderFactory.php';
2122

phpmd.xml.dist

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<exclude name="ExitExpression"/>
2727
</rule>
2828
<rule ref="rulesets/naming.xml">
29+
<exclude name="ShortMethodName"/>
2930
<exclude name="LongVariable"/>
3031
<exclude name="ShortVariable"/>
3132
<exclude name="ConstantNamingConventions"/>

src/Core/OAuth1Provider.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected function getRequestTokenRequestParams():array{
101101
*
102102
* @throws \chillerlan\OAuth\Providers\ProviderException
103103
*/
104-
protected function parseTokenResponse(ResponseInterface $response, bool $checkCallbackConfirmed = false):AccessToken{
104+
protected function parseTokenResponse(ResponseInterface $response, bool|null $checkCallbackConfirmed = null):AccessToken{
105105
$data = QueryUtil::parse(MessageUtil::decompress($response));
106106

107107
if(empty($data)){
@@ -122,7 +122,10 @@ protected function parseTokenResponse(ResponseInterface $response, bool $checkCa
122122
}
123123

124124
// MUST be present and set to "true". The parameter is used to differentiate from previous versions of the protocol
125-
if($checkCallbackConfirmed && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true')){
125+
if(
126+
$checkCallbackConfirmed === true
127+
&& (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true')
128+
){
126129
throw new ProviderException('invalid OAuth 1.0a response');
127130
}
128131

src/Core/OAuth2Provider.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ protected function getRefreshAccessTokenRequestBodyParams(string $refreshToken):
417417
* @throws \chillerlan\OAuth\Providers\ProviderException
418418
*/
419419
public function invalidateAccessToken(AccessToken $token = null, string|null $type = null):bool{
420-
$type = strtolower(trim($type ?? 'access_token'));
420+
$type = strtolower(trim(($type ?? 'access_token')));
421421

422422
// @link https://datatracker.ietf.org/doc/html/rfc7009#section-2.1
423423
if(!in_array($type, ['access_token', 'refresh_token'])){
@@ -587,7 +587,10 @@ final public function setCodeVerifier(array $params):array{
587587
/**
588588
* @implements \chillerlan\OAuth\Core\PKCE::generateVerifier()
589589
* @see \chillerlan\OAuth\Core\OAuth2Provider::setCodeChallenge()
590+
*
590591
* @phan-suppress PhanUndeclaredClassMethod, PhanUndeclaredMethod
592+
* @noinspection PhpFullyQualifiedNameUsageInspection
593+
* @SuppressWarnings(PHPMD.MissingImport)
591594
*/
592595
final public function generateVerifier(int $length):string{
593596

src/Core/Utilities.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Utilities{
4646
* Fetches a list of provider classes in the given directory
4747
*/
4848
public static function getProviders(string|null $providerDir = null, string|null $namespace = null):array{
49-
$providerDir = realpath($providerDir ?? __DIR__.'/../Providers');
49+
$providerDir = realpath(($providerDir ?? __DIR__.'/../Providers'));
5050
$namespace = trim(($namespace ?? 'chillerlan\\OAuth\\Providers'), '\\');
5151
$providers = [];
5252

src/OAuthOptions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use chillerlan\Settings\SettingsContainerAbstract;
1515

1616
/**
17-
* This class holds all settings related to the OAuth provider as well as the default HTTP client.
17+
* This class holds all settings related to the OAuth provider
1818
*/
1919
class OAuthOptions extends SettingsContainerAbstract{
2020
use OAuthOptionsTrait;

src/Providers/LastFM.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function request(
156156
array|null $headers = null,
157157
string|null $protocolVersion = null
158158
):ResponseInterface{
159-
$method = strtoupper($method ?? 'GET');
159+
$method = strtoupper(($method ?? 'GET'));
160160
$headers ??= [];
161161

162162
if($body !== null && !is_array($body)){
@@ -345,7 +345,7 @@ public function clearScrobbles():static{
345345
*/
346346
protected function parseTrack(array $track):array{
347347
// we're using the settings container and its setters to enforce variables and types etc.
348-
return (new class($track) extends SettingsContainerAbstract{
348+
$parser = new class ($track) extends SettingsContainerAbstract{
349349

350350
protected string $artist;
351351
protected string $track;
@@ -410,7 +410,9 @@ protected function set_duration(int $duration):void{
410410
$this->duration = $duration;
411411
}
412412

413-
})->toArray();
413+
};
414+
415+
return $parser->toArray();
414416
}
415417

416418
/**

tests/Attributes/Provider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @copyright 2024 smiley
88
* @license MIT
99
*/
10-
declare(strict_types = 1);
10+
declare(strict_types=1);
1111

1212
namespace chillerlan\OAuthTest\Attributes;
1313

tests/Core/AuthenticatedUserTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testClassIsReadOnly():void{
4242

4343
// cannot overwrite via fromIterable()
4444
$userdata = [
45-
'id' => 456,
45+
'id' => 456,
4646
'userName' => 'nope',
4747
'email' => '[email protected]',
4848
];

tests/Providers/ProviderUnitTestAbstract.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,13 @@ protected function getMockHttpClient(ResponseInterface $response):ClientInterfac
163163

164164
public function __construct(
165165
private readonly ResponseInterface $mockedResponse
166-
){}
166+
){
167+
// noop
168+
}
167169

168170
public function sendRequest(RequestInterface $request):ResponseInterface{
169171
return $this->mockedResponse;
170172
}
171-
172173
};
173174
}
174175

tests/Providers/Unit/LastFMTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ final class LastFMTest extends OAuthProviderUnitTestAbstract{
2424

2525
protected const TEST_TOKEN = '{"session":{"name":"lfm-user","key":"sk","subscriber":0}}';
2626

27+
// PHPCS:ignore
2728
protected const SCROBBLE_RESPONSE_SINGLE =
2829
'{"scrobbles":{"scrobble":{"artist":{"corrected":"0","#text":"Helium"},"album":{"corrected":"0"},'.
2930
'"track":{"corrected":"0","#text":"Vibrations"},"ignoredMessage":{"code":"0","#text":""},'.
3031
'"albumArtist":{"corrected":"0","#text":""},"timestamp":"1712992925"},"@attr":{"ignored":0,"accepted":1}}}';
3132

33+
// PHPCS:ignore
3234
protected const SCROBBLE_RESPONSE_MULTI =
3335
'{"scrobbles":{"scrobble":[{"artist":{"corrected":"0","#text":"Helium"},"album":{"corrected":"0"},'.
3436
'"track":{"corrected":"0","#text":"Vibrations"},"ignoredMessage":{"code":"0","#text":""},'.

0 commit comments

Comments
 (0)