Passed
Push — master ( 02afac...cc7fc1 )
by smiley
01:35
created
src/Core/OAuthProvider.php 2 patches
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,24 +290,24 @@  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 296
 			// @todo: content type support
297
-			if($contentType === 'application/x-www-form-urlencoded'){
297
+			if ($contentType === 'application/x-www-form-urlencoded') {
298 298
 				$body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738));
299 299
 			}
300
-			elseif($contentType === 'application/json'){
300
+			elseif ($contentType === 'application/json') {
301 301
 				$body = $this->streamFactory->createStream(json_encode($body));
302 302
 			}
303 303
 
304 304
 		}
305 305
 
306
-		foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){
306
+		foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) {
307 307
 			$request = $request->withAddedHeader($header, $value);
308 308
 		}
309 309
 
310
-		if($body instanceof StreamInterface){
310
+		if ($body instanceof StreamInterface) {
311 311
 			$request = $request->withBody($body);
312 312
 		}
313 313
 
@@ -322,11 +322,11 @@  discard block
 block discarded – undo
322 322
 	public function sendRequest(RequestInterface $request):ResponseInterface{
323 323
 
324 324
 		// get authorization only if we request the provider API
325
-		if(strpos((string)$request->getUri(), $this->apiURL) === 0){
325
+		if (strpos((string)$request->getUri(), $this->apiURL) === 0) {
326 326
 			$token = $this->storage->getAccessToken($this->serviceName);
327 327
 
328 328
 			// attempt to refresh an expired token
329
-			if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){
329
+			if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) {
330 330
 				$token = $this->refreshAccessToken($token);
331 331
 			}
332 332
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -296,8 +296,7 @@
 block discarded – undo
296 296
 			// @todo: content type support
297 297
 			if($contentType === 'application/x-www-form-urlencoded'){
298 298
 				$body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738));
299
-			}
300
-			elseif($contentType === 'application/json'){
299
+			} elseif($contentType === 'application/json'){
301 300
 				$body = $this->streamFactory->createStream(json_encode($body));
302 301
 			}
303 302
 
Please login to merge, or discard this patch.