Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 61a6ec1

Browse files
committed
:octocat: use function/const
1 parent f23b679 commit 61a6ec1

File tree

14 files changed

+92
-55
lines changed

14 files changed

+92
-55
lines changed

src/BattleNet/BattleNet.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use Psr\Http\Client\ClientInterface;
2121
use Psr\Log\LoggerInterface;
2222

23+
use function in_array, strtolower;
24+
2325
/**
2426
* @method \Psr\Http\Message\ResponseInterface userinfo(array $params = ['access_token'])
2527
*/
@@ -56,9 +58,9 @@ public function __construct(ClientInterface $http, OAuthStorageInterface $storag
5658
* @throws \chillerlan\OAuth\Core\ProviderException
5759
*/
5860
public function setRegion(string $region):BattleNet{
59-
$region = \strtolower($region);
61+
$region = strtolower($region);
6062

61-
if(!\in_array($region, ['apac', 'cn', 'eu', 'us'], true)){
63+
if(!in_array($region, ['apac', 'cn', 'eu', 'us'], true)){
6264
throw new ProviderException('invalid region: '.$region);
6365
}
6466

src/Deezer/Deezer.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717

1818
namespace chillerlan\OAuth\Providers\Deezer;
1919

20-
use chillerlan\HTTP\Psr7;
2120
use chillerlan\OAuth\Core\{AccessToken, CSRFToken, OAuth2Provider, ProviderException, TokenExpires};
2221
use Psr\Http\Message\{ResponseInterface, UriInterface};
2322

23+
use function array_merge, http_build_query, implode, is_array, parse_str;
24+
use function chillerlan\HTTP\Psr7\{decompress_content, merge_query};
25+
26+
use const PHP_QUERY_RFC1738;
27+
2428
/**
2529
* @method \Psr\Http\Message\ResponseInterface me()
2630
*/
@@ -53,16 +57,16 @@ public function getAuthURL(array $params = null, array $scopes = null):UriInterf
5357
unset($params['client_secret']);
5458
}
5559

56-
$params = \array_merge($params, [
60+
$params = array_merge($params, [
5761
'app_id' => $this->options->key,
5862
'redirect_uri' => $this->options->callbackURL,
59-
'perms' => \implode($this->scopesDelimiter, $scopes),
63+
'perms' => implode($this->scopesDelimiter, $scopes),
6064
# 'response_type' => 'token', // -> token in hash fragment
6165
]);
6266

6367
$params = $this->setState($params);
6468

65-
return $this->uriFactory->createUri(Psr7\merge_query($this->authURL, $params));
69+
return $this->uriFactory->createUri(merge_query($this->authURL, $params));
6670
}
6771

6872
/**
@@ -82,7 +86,7 @@ public function getAccessToken(string $code, string $state = null):AccessToken{
8286
->createRequest('POST', $this->accessTokenURL)
8387
->withHeader('Content-Type', 'application/x-www-form-urlencoded')
8488
->withHeader('Accept-Encoding', 'identity')
85-
->withBody($this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738)));
89+
->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)));
8690

8791
$token = $this->parseTokenResponse($this->http->sendRequest($request));
8892

@@ -95,9 +99,9 @@ public function getAccessToken(string $code, string $state = null):AccessToken{
9599
* @inheritDoc
96100
*/
97101
protected function parseTokenResponse(ResponseInterface $response):AccessToken{
98-
\parse_str(Psr7\decompress_content($response), $data);
102+
parse_str(decompress_content($response), $data);
99103

100-
if(!\is_array($data) || empty($data)){
104+
if(!is_array($data) || empty($data)){
101105
throw new ProviderException('unable to parse token response');
102106
}
103107

src/Discogs/Discogs.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515

1616
namespace chillerlan\OAuth\Providers\Discogs;
1717

18-
use chillerlan\HTTP\Psr7;
1918
use chillerlan\OAuth\Core\{AccessToken, OAuth1Provider};
2019
use DateTime;
2120

21+
use function chillerlan\HTTP\Psr7\build_http_query;
22+
2223
/**
2324
* @method \Psr\Http\Message\ResponseInterface artist(string $artist_id)
2425
* @method \Psr\Http\Message\ResponseInterface artistReleases(string $artist_id, array $params = ['page', 'per_page', 'sort', 'sort_order'])
@@ -101,7 +102,7 @@ public function getRequestToken():AccessToken{
101102

102103
$request = $this->requestFactory
103104
->createRequest('POST', $this->requestTokenURL)
104-
->withHeader('Authorization', 'OAuth '.Psr7\build_http_query($params, true, ', ', '"'));
105+
->withHeader('Authorization', 'OAuth '.build_http_query($params, true, ', ', '"'));
105106
;
106107

107108
return $this->parseTokenResponse($this->http->sendRequest($request), true);

src/Flickr/Flickr.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515

1616
namespace chillerlan\OAuth\Providers\Flickr;
1717

18-
use chillerlan\HTTP\Psr7;
1918
use chillerlan\OAuth\Core\OAuth1Provider;
2019
use Psr\Http\Message\ResponseInterface;
2120

21+
use function chillerlan\HTTP\Psr7\merge_query;
22+
2223
/**
2324
* @method \Psr\Http\Message\ResponseInterface activityUserComments(array $params = ['per_page', 'page'])
2425
* @method \Psr\Http\Message\ResponseInterface activityUserPhotos(array $params = ['timeframe', 'per_page', 'page'])
@@ -276,7 +277,7 @@ public function request(string $path, array $params = null, string $method = nul
276277
'nojsoncallback' => true,
277278
]);
278279

279-
$request = $this->requestFactory->createRequest($method, Psr7\merge_query($this->apiURL, $params));
280+
$request = $this->requestFactory->createRequest($method, merge_query($this->apiURL, $params));
280281

281282
$request = $this->getRequestAuthorization($request, $this->storage->getAccessToken($this->serviceName));
282283

src/Foursquare/Foursquare.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
use chillerlan\OAuth\Core\OAuth2Provider;
1919
use Psr\Http\Message\ResponseInterface;
2020

21+
use function array_merge, explode, parse_str, parse_url;
22+
23+
use const PHP_URL_QUERY;
24+
2125
/**
2226
* @method \Psr\Http\Message\ResponseInterface me()
2327
*/
@@ -45,12 +49,12 @@ class Foursquare extends OAuth2Provider{
4549
*/
4650
public function request(string $path, array $params = null, string $method = null, $body = null, array $headers = null):ResponseInterface{
4751

48-
\parse_str(\parse_url($this->apiURL.$path, \PHP_URL_QUERY), $query);
52+
parse_str(parse_url($this->apiURL.$path, PHP_URL_QUERY), $query);
4953

5054
$query['v'] = $this::API_VERSIONDATE;
5155
$query['m'] = 'foursquare';
5256

53-
return parent::request(\explode('?', $path)[0], \array_merge($params ?? [], $query), $method, $body, $headers);
57+
return parent::request(explode('?', $path)[0], array_merge($params ?? [], $query), $method, $body, $headers);
5458
}
5559

5660
}

src/GuildWars2/GuildWars2.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
namespace chillerlan\OAuth\Providers\GuildWars2;
1919

20-
use chillerlan\HTTP\Psr7;
2120
use chillerlan\OAuth\Core\{AccessToken, OAuth2Provider, ProviderException};
2221
use Psr\Http\Message\UriInterface;
2322

23+
use function implode, preg_match, substr;
24+
use function chillerlan\HTTP\Psr7\{get_json, merge_query};
25+
2426
/**
2527
* @method \Psr\Http\Message\ResponseInterface account(array $params = ['access_token'])
2628
* @method \Psr\Http\Message\ResponseInterface accountAchievements(array $params = ['access_token'])
@@ -265,12 +267,12 @@ public function storeGW2Token(string $access_token):AccessToken{
265267
}
266268

267269
$request = $this->requestFactory
268-
->createRequest('GET', Psr7\merge_query($this->apiURL.'/tokeninfo', ['access_token' => $access_token]))
270+
->createRequest('GET', merge_query($this->apiURL.'/tokeninfo', ['access_token' => $access_token]))
269271
;
270272

271-
$tokeninfo = Psr7\get_json($this->http->sendRequest($request));
273+
$tokeninfo = get_json($this->http->sendRequest($request));
272274

273-
if(isset($tokeninfo->id) && strpos($access_token, $tokeninfo->id) === 0){
275+
if(isset($tokeninfo->id) && \strpos($access_token, $tokeninfo->id) === 0){
274276

275277
$token = new AccessToken([
276278
'provider' => $this->serviceName,
@@ -309,5 +311,4 @@ public function getAccessToken(string $code, string $state = null):AccessToken{
309311
throw new ProviderException($this::AUTH_ERRMSG);
310312
}
311313

312-
313314
}

src/LastFM/LastFM.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414

1515
namespace chillerlan\OAuth\Providers\LastFM;
1616

17-
use chillerlan\HTTP\Psr7;
1817
use chillerlan\OAuth\Core\{AccessToken, OAuthProvider, ProviderException};
1918
use Psr\Http\Message\{RequestInterface, ResponseInterface, UriInterface};
2019

20+
use function array_merge, http_build_query, in_array, is_array,ksort, md5;
21+
use function chillerlan\HTTP\Psr7\{get_json, merge_query};
22+
23+
use const PHP_QUERY_RFC1738;
24+
2125
/**
2226
* @method \Psr\Http\Message\ResponseInterface albumAddTags(array $body = ['mbid', 'album', 'artist', 'tags'])
2327
* @method \Psr\Http\Message\ResponseInterface albumGetInfo(array $params = ['mbid', 'album', 'artist', 'username', 'lang', 'autocorrect'])
@@ -102,11 +106,11 @@ class LastFM extends OAuthProvider{
102106
*/
103107
public function getAuthURL(array $params = null):UriInterface{
104108

105-
$params = \array_merge($params ?? [], [
109+
$params = array_merge($params ?? [], [
106110
'api_key' => $this->options->key,
107111
]);
108112

109-
return $this->uriFactory->createUri(Psr7\merge_query($this->authURL, $params));
113+
return $this->uriFactory->createUri(merge_query($this->authURL, $params));
110114
}
111115

112116
/**
@@ -115,17 +119,17 @@ public function getAuthURL(array $params = null):UriInterface{
115119
* @return string
116120
*/
117121
protected function getSignature(array $params):string {
118-
\ksort($params);
122+
ksort($params);
119123

120124
$signature = '';
121125

122126
foreach($params as $k => $v){
123-
if(!\in_array($k, ['format', 'callback'])){
127+
if(!in_array($k, ['format', 'callback'])){
124128
$signature .= $k.$v;
125129
}
126130
}
127131

128-
return \md5($signature.$this->options->secret);
132+
return md5($signature.$this->options->secret);
129133
}
130134

131135
/**
@@ -144,7 +148,7 @@ public function getAccessToken(string $session_token):AccessToken{
144148

145149
$params['api_sig'] = $this->getSignature($params);
146150

147-
$request = $this->requestFactory->createRequest('GET', Psr7\merge_query($this->apiURL, $params));
151+
$request = $this->requestFactory->createRequest('GET', merge_query($this->apiURL, $params));
148152

149153
return $this->parseTokenResponse($this->http->sendRequest($request));
150154
}
@@ -156,9 +160,9 @@ public function getAccessToken(string $session_token):AccessToken{
156160
* @throws \chillerlan\OAuth\Core\ProviderException
157161
*/
158162
protected function parseTokenResponse(ResponseInterface $response):AccessToken{
159-
$data = Psr7\get_json($response, true);
163+
$data = get_json($response, true);
160164

161-
if(!$data || !\is_array($data)){
165+
if(!$data || !is_array($data)){
162166
throw new ProviderException('unable to parse token response');
163167
}
164168
elseif(isset($data['error'])){
@@ -192,7 +196,7 @@ protected function parseTokenResponse(ResponseInterface $response):AccessToken{
192196
*/
193197
protected function requestParams(string $apiMethod, array $params, array $body):array {
194198

195-
$params = \array_merge($params, $body, [
199+
$params = array_merge($params, $body, [
196200
'method' => $apiMethod,
197201
'format' => 'json',
198202
'api_key' => $this->options->key,
@@ -222,15 +226,15 @@ public function request(string $path, array $params = null, string $method = nul
222226
$params = [];
223227
}
224228

225-
$request = $this->requestFactory->createRequest($method, Psr7\merge_query($this->apiURL, $params));
229+
$request = $this->requestFactory->createRequest($method, merge_query($this->apiURL, $params));
226230

227-
foreach(\array_merge($this->apiHeaders, $headers ?? []) as $header => $value){
231+
foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){
228232
$request = $request->withAddedHeader($header, $value);
229233
}
230234

231235
if($method === 'POST'){
232236
$request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
233-
$body = $this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738));
237+
$body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738));
234238
$request = $request->withBody($body);
235239
}
236240

src/MailChimp/MailChimp.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515

1616
namespace chillerlan\OAuth\Providers\MailChimp;
1717

18-
use chillerlan\HTTP\Psr7;
1918
use chillerlan\OAuth\Core\{AccessToken, CSRFToken, OAuth2Provider};
2019
use chillerlan\OAuth\OAuthException;
2120
use Psr\Http\Message\ResponseInterface;
2221

22+
use function array_merge, sprintf;
23+
use function chillerlan\HTTP\Psr7\get_json;
24+
2325
/**
2426
* @method \Psr\Http\Message\ResponseInterface createAuthorizedApp(array $body = ['client_id', 'client_secret'])
2527
* @method \Psr\Http\Message\ResponseInterface getAuthorizedApp(array $params = ['fields', 'exclude_fields'])
@@ -64,7 +66,7 @@ public function getTokenMetadata(AccessToken $token = null):AccessToken{
6466
throw new OAuthException('metadata response error'); // @codeCoverageIgnore
6567
}
6668

67-
$token->extraParams = \array_merge($token->extraParams, Psr7\get_json($response, true));
69+
$token->extraParams = array_merge($token->extraParams, get_json($response, true));
6870

6971
$this->storage->storeAccessToken($this->serviceName, $token);
7072

@@ -79,7 +81,7 @@ public function getTokenMetadata(AccessToken $token = null):AccessToken{
7981
public function request(string $path, array $params = null, string $method = null, $body = null, array $headers = null):ResponseInterface{
8082
$token = $this->storage->getAccessToken($this->serviceName);
8183

82-
$this->apiURL = \sprintf($this::API_BASE, $token->extraParams['dc']);
84+
$this->apiURL = sprintf($this::API_BASE, $token->extraParams['dc']);
8385

8486
return parent::request($path, $params, $method, $body, $headers);
8587
}

src/Mastodon/Mastodon.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use chillerlan\OAuth\Core\{CSRFToken, OAuth2Provider, TokenExpires, TokenRefresh};
1919
use chillerlan\OAuth\OAuthException;
2020

21+
use function parse_url;
22+
2123
/**
2224
* @method \Psr\Http\Message\ResponseInterface acceptFollowRequest(string $request_id)
2325
* @method \Psr\Http\Message\ResponseInterface addListMembers(string $list_id, array $body = ['account_ids'])

src/MusicBrainz/MusicBrainz.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
use chillerlan\OAuth\Core\{AccessToken, CSRFToken, OAuth2Provider, ProviderException, TokenExpires, TokenRefresh};
1919
use Psr\Http\Message\ResponseInterface;
20+
21+
use function array_merge, date, explode, http_build_query, in_array, sprintf, strtoupper;
22+
23+
use const PHP_QUERY_RFC1738;
24+
2025
/**
2126
* @method \Psr\Http\Message\ResponseInterface area(array $params = ['inc', 'query', 'limit', 'offset', 'collection'])
2227
* @method \Psr\Http\Message\ResponseInterface areaId(string $id, array $params = ['inc'])
@@ -88,7 +93,7 @@ public function refreshAccessToken(AccessToken $token = null):AccessToken{
8893
$refreshToken = $token->refreshToken;
8994

9095
if(empty($refreshToken)){
91-
throw new ProviderException(\sprintf('no refresh token available, token expired [%s]', \date('Y-m-d h:i:s A', $token->expires)));
96+
throw new ProviderException(sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires)));
9297
}
9398

9499
$body = [
@@ -102,7 +107,7 @@ public function refreshAccessToken(AccessToken $token = null):AccessToken{
102107
->createRequest('POST', $this->refreshTokenURL ?? $this->accessTokenURL) // refreshTokenURL is used in tests
103108
->withHeader('Content-Type', 'application/x-www-form-urlencoded')
104109
->withHeader('Accept-Encoding', 'identity')
105-
->withBody($this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738)))
110+
->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)))
106111
;
107112

108113
$newToken = $this->parseTokenResponse($this->http->sendRequest($request));
@@ -127,7 +132,7 @@ public function refreshAccessToken(AccessToken $token = null):AccessToken{
127132
*/
128133
public function request(string $path, array $params = null, string $method = null, $body = null, array $headers = null):ResponseInterface{
129134
$params = $params ?? [];
130-
$method = \strtoupper($method);
135+
$method = strtoupper($method);
131136
$token = $this->storage->getAccessToken($this->serviceName);
132137

133138
if($token->isExpired()){
@@ -138,13 +143,13 @@ public function request(string $path, array $params = null, string $method = nul
138143
$params['fmt'] = 'json';
139144
}
140145

141-
if(\in_array($method, ['POST', 'PUT', 'DELETE']) && !isset($params['client'])){
146+
if(in_array($method, ['POST', 'PUT', 'DELETE']) && !isset($params['client'])){
142147
$params['client'] = $this->options->user_agent; // @codeCoverageIgnore
143148
}
144149

145-
$headers = \array_merge($this->apiHeaders, $headers ?? [], ['Authorization' => 'Bearer '.$token->accessToken]);
150+
$headers = array_merge($this->apiHeaders, $headers ?? [], ['Authorization' => 'Bearer '.$token->accessToken]);
146151

147-
return parent::request(\explode('?', $path)[0], $params, $method, $body, $headers);
152+
return parent::request(explode('?', $path)[0], $params, $method, $body, $headers);
148153
}
149154

150155
}

0 commit comments

Comments
 (0)