99use OAuth \Common \Http \Url ;
1010use OAuth \Common \Service \AbstractService as BaseAbstractService ;
1111use OAuth \Common \Storage \TokenStorageInterface ;
12+ use OAuth \Common \Token \AbstractToken ;
1213use OAuth \Common \Token \Exception \ExpiredTokenException ;
1314use OAuth \Common \Token \TokenInterface ;
1415use OAuth \OAuth2 \Service \Exception \InvalidAuthorizationStateException ;
@@ -102,12 +103,12 @@ abstract protected function parseAccessTokenResponse($responseBody);
102103 public function getAuthorizationUri (array $ additionalParameters = [])
103104 {
104105 $ parameters = array_merge (
105- array (
106+ [
106107 'type ' => 'web_server ' ,
107108 'client_id ' => $ this ->credentials ->getConsumerId (),
108109 'redirect_uri ' => $ this ->credentials ->getCallbackUrl (),
109110 'response_type ' => 'code ' ,
110- ) ,
111+ ] ,
111112 $ additionalParameters
112113 );
113114
@@ -137,12 +138,10 @@ public function getAuthorizationUri(array $additionalParameters = [])
137138 public function request ($ path , array $ body = [], $ method = 'GET ' , array $ extraHeaders = [])
138139 {
139140 $ uri = $ this ->determineRequestUriFromPath ($ path );
141+ /** @var AbstractToken $token */
140142 $ token = $ this ->storage ->retrieveAccessToken ($ this ->service ());
141143
142- if ($ token ->getEndOfLife () !== TokenInterface::EOL_NEVER_EXPIRES
143- && $ token ->getEndOfLife () !== TokenInterface::EOL_UNKNOWN
144- && time () > $ token ->getEndOfLife ()
145- )
144+ if ($ token ->isExpired ())
146145 {
147146 throw new ExpiredTokenException (
148147 sprintf (
@@ -156,23 +155,23 @@ public function request($path, array $body = [], $method = 'GET', array $extraHe
156155 // add the token where it may be needed
157156 if (static ::AUTHORIZATION_METHOD_HEADER_OAUTH === $ this ->getAuthorizationMethod ())
158157 {
159- $ extraHeaders = array_merge (array ( 'Authorization ' => 'OAuth ' . $ token ->getAccessToken ()) , $ extraHeaders );
158+ $ extraHeaders = array_merge ([ 'Authorization ' => 'OAuth ' . $ token ->getAccessToken ()] , $ extraHeaders );
160159 }
161160 elseif (static ::AUTHORIZATION_METHOD_QUERY_STRING === $ this ->getAuthorizationMethod ())
162161 {
163- $ uri ->getQuery ()->modify (array ( 'access_token ' => $ token ->getAccessToken ()) );
162+ $ uri ->getQuery ()->modify ([ 'access_token ' => $ token ->getAccessToken ()] );
164163 }
165164 elseif (static ::AUTHORIZATION_METHOD_QUERY_STRING_V2 === $ this ->getAuthorizationMethod ())
166165 {
167- $ uri ->getQuery ()->modify (array ( 'oauth2_access_token ' => $ token ->getAccessToken ()) );
166+ $ uri ->getQuery ()->modify ([ 'oauth2_access_token ' => $ token ->getAccessToken ()] );
168167 }
169168 elseif (static ::AUTHORIZATION_METHOD_QUERY_STRING_V3 === $ this ->getAuthorizationMethod ())
170169 {
171- $ uri ->getQuery ()->modify (array ( 'apikey ' => $ token ->getAccessToken ()) );
170+ $ uri ->getQuery ()->modify ([ 'apikey ' => $ token ->getAccessToken ()] );
172171 }
173172 elseif (static ::AUTHORIZATION_METHOD_HEADER_BEARER === $ this ->getAuthorizationMethod ())
174173 {
175- $ extraHeaders = array_merge (array ( 'Authorization ' => 'Bearer ' . $ token ->getAccessToken ()) , $ extraHeaders );
174+ $ extraHeaders = array_merge ([ 'Authorization ' => 'Bearer ' . $ token ->getAccessToken ()] , $ extraHeaders );
176175 }
177176
178177 $ extraHeaders = array_merge ($ this ->getExtraApiHeaders (), $ extraHeaders );
@@ -200,13 +199,13 @@ public function requestAccessToken($code, $state = NULL)
200199 $ this ->validateAuthorizationState ($ state );
201200 }
202201
203- $ bodyParams = array (
202+ $ bodyParams = [
204203 'code ' => $ code ,
205204 'client_id ' => $ this ->credentials ->getConsumerId (),
206205 'client_secret ' => $ this ->credentials ->getConsumerSecret (),
207206 'redirect_uri ' => $ this ->credentials ->getCallbackUrl (),
208207 'grant_type ' => 'authorization_code ' ,
209- ) ;
208+ ] ;
210209
211210 $ responseBody = $ this ->httpRequest (
212211 $ this ->getAccessTokenEndpoint (),
@@ -236,13 +235,13 @@ public function refreshAccessToken(TokenInterface $token)
236235 throw new MissingRefreshTokenException ();
237236 }
238237
239- $ parameters = array (
238+ $ parameters = [
240239 'grant_type ' => 'refresh_token ' ,
241240 'type ' => 'web_server ' ,
242241 'client_id ' => $ this ->credentials ->getConsumerId (),
243242 'client_secret ' => $ this ->credentials ->getConsumerSecret (),
244243 'refresh_token ' => $ refreshToken ,
245- ) ;
244+ ] ;
246245
247246 $ responseBody = $ this ->httpRequest (
248247 $ this ->getAccessTokenEndpoint (),
0 commit comments