1414
1515namespace chillerlan \OAuth \Providers \LastFM ;
1616
17- use chillerlan \HTTP \Psr7 ;
1817use chillerlan \OAuth \Core \{AccessToken , OAuthProvider , ProviderException };
1918use 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
0 commit comments