Passed
Push — master ( 56090f...02afac )
by smiley
01:24
created
src/Core/OAuthProvider.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 *
123 123
 	 * @throws \chillerlan\HTTP\MagicAPI\ApiClientException
124 124
 	 */
125
-	public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null){
125
+	public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null) {
126 126
 		$this->http    = $http;
127 127
 		$this->storage = $storage;
128 128
 		$this->options = $options;
@@ -134,10 +134,10 @@  discard block
 block discarded – undo
134 134
 
135 135
 		$this->serviceName = (new ReflectionClass($this))->getShortName();
136 136
 
137
-		if($this instanceof ApiClientInterface && !empty($this->endpointMap) && class_exists($this->endpointMap)){
137
+		if ($this instanceof ApiClientInterface && !empty($this->endpointMap) && class_exists($this->endpointMap)) {
138 138
 			$this->endpoints = new $this->endpointMap;
139 139
 
140
-			if(!$this->endpoints instanceof EndpointMapInterface){
140
+			if (!$this->endpoints instanceof EndpointMapInterface) {
141 141
 				throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore
142 142
 			}
143 143
 
@@ -150,9 +150,9 @@  discard block
 block discarded – undo
150 150
 	 *
151 151
 	 * @return string|null
152 152
 	 */
153
-	public function __get(string $name):?string{
153
+	public function __get(string $name): ?string{
154 154
 
155
-		if(!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL', 'apiURL'], true)){
155
+		if (!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL', 'apiURL'], true)) {
156 156
 			return null;
157 157
 		}
158 158
 
@@ -209,11 +209,11 @@  discard block
 block discarded – undo
209 209
 	 */
210 210
 	public function __call(string $name, array $arguments):ResponseInterface{
211 211
 
212
-		if(!$this instanceof ApiClientInterface){
212
+		if (!$this instanceof ApiClientInterface) {
213 213
 			throw new ApiClientException('MagicAPI not available');
214 214
 		}
215 215
 
216
-		if(!$this->endpoints->__isset($name)){
216
+		if (!$this->endpoints->__isset($name)) {
217 217
 			throw new ApiClientException('endpoint not found');
218 218
 		}
219 219
 
@@ -226,21 +226,21 @@  discard block
 block discarded – undo
226 226
 		$path_elements = $m['path_elements'] ?? [];
227 227
 		$params_in_url = count($path_elements);
228 228
 		$params        = $arguments[$params_in_url] ?? [];
229
-		$urlparams     = array_slice($arguments,0 , $params_in_url);
229
+		$urlparams     = array_slice($arguments, 0, $params_in_url);
230 230
 
231
-		if($params_in_url > 0){
231
+		if ($params_in_url > 0) {
232 232
 
233
-			if(count($urlparams) < $params_in_url){
233
+			if (count($urlparams) < $params_in_url) {
234 234
 				throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements));
235 235
 			}
236 236
 
237 237
 			$endpoint = sprintf($endpoint, ...$urlparams);
238 238
 		}
239 239
 
240
-		if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){
240
+		if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) {
241 241
 			$body = $arguments[$params_in_url + 1] ?? $params;
242 242
 
243
-			if($params === $body){
243
+			if ($params === $body) {
244 244
 				$params = [];
245 245
 			}
246 246
 
@@ -290,23 +290,23 @@  discard block
 block discarded – undo
290 290
 		$request = $this->requestFactory
291 291
 			->createRequest($method ?? 'GET', Psr7\merge_query($this->apiURL.$path, $params ?? []));
292 292
 
293
-		if(is_array($body) && $request->hasHeader('content-type')){
293
+		if (is_array($body) && $request->hasHeader('content-type')) {
294 294
 			$contentType = strtolower($request->getHeaderLine('content-type'));
295 295
 
296
-			if($contentType === 'application/x-www-form-urlencoded'){
296
+			if ($contentType === 'application/x-www-form-urlencoded') {
297 297
 				$body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738));
298 298
 			}
299
-			elseif($contentType === 'application/json'){
299
+			elseif ($contentType === 'application/json') {
300 300
 				$body = $this->streamFactory->createStream(json_encode($body));
301 301
 			}
302 302
 
303 303
 		}
304 304
 
305
-		foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){
305
+		foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) {
306 306
 			$request = $request->withAddedHeader($header, $value);
307 307
 		}
308 308
 
309
-		if($body instanceof StreamInterface){
309
+		if ($body instanceof StreamInterface) {
310 310
 			$request = $request->withBody($body);
311 311
 		}
312 312
 
@@ -321,11 +321,11 @@  discard block
 block discarded – undo
321 321
 	public function sendRequest(RequestInterface $request):ResponseInterface{
322 322
 
323 323
 		// get authorization only if we request the provider API
324
-		if($request->getUri()->getHost() === parse_url($this->apiURL, PHP_URL_HOST)){
324
+		if ($request->getUri()->getHost() === parse_url($this->apiURL, PHP_URL_HOST)) {
325 325
 			$token = $this->storage->getAccessToken($this->serviceName);
326 326
 
327 327
 			// attempt to refresh an expired token
328
-			if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){
328
+			if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) {
329 329
 				$token = $this->refreshAccessToken($token);
330 330
 			}
331 331
 
Please login to merge, or discard this patch.