Passed
Push — master ( 7ff4d9...b6dab2 )
by smiley
01:25
created
src/Core/OAuthProvider.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	 *
141 141
 	 * @throws \chillerlan\HTTP\MagicAPI\ApiClientException
142 142
 	 */
143
-	public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null){
143
+	public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null) {
144 144
 		$this->http    = $http;
145 145
 		$this->storage = $storage;
146 146
 		$this->options = $options;
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
 
153 153
 		$this->serviceName = (new ReflectionClass($this))->getShortName();
154 154
 
155
-		if($this instanceof ApiClientInterface && !empty($this->endpointMap) && \class_exists($this->endpointMap)){
155
+		if ($this instanceof ApiClientInterface && !empty($this->endpointMap) && \class_exists($this->endpointMap)) {
156 156
 			$this->endpoints = new $this->endpointMap;
157 157
 
158
-			if(!$this->endpoints instanceof EndpointMapInterface){
158
+			if (!$this->endpoints instanceof EndpointMapInterface) {
159 159
 				throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore
160 160
 			}
161 161
 
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
 	 *
169 169
 	 * @return mixed|null
170 170
 	 */
171
-	public function __get(string $name){
171
+	public function __get(string $name) {
172 172
 
173
-		if(\in_array($name, $this::ALLOWED_PROPERTIES, true)){
173
+		if (\in_array($name, $this::ALLOWED_PROPERTIES, true)) {
174 174
 			return $this->{$name};
175 175
 		}
176 176
 
@@ -227,11 +227,11 @@  discard block
 block discarded – undo
227 227
 	 */
228 228
 	public function __call(string $name, array $arguments):ResponseInterface{
229 229
 
230
-		if(!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap){
230
+		if (!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap) {
231 231
 			throw new ApiClientException('MagicAPI not available');
232 232
 		}
233 233
 
234
-		if(!$this->endpoints->__isset($name)){
234
+		if (!$this->endpoints->__isset($name)) {
235 235
 			throw new ApiClientException('endpoint not found: "'.$name.'"');
236 236
 		}
237 237
 
@@ -244,21 +244,21 @@  discard block
 block discarded – undo
244 244
 		$path_elements = $m['path_elements'] ?? [];
245 245
 		$params_in_url = \count($path_elements);
246 246
 		$params        = $arguments[$params_in_url] ?? [];
247
-		$urlparams     = \array_slice($arguments,0 , $params_in_url);
247
+		$urlparams     = \array_slice($arguments, 0, $params_in_url);
248 248
 
249
-		if($params_in_url > 0){
249
+		if ($params_in_url > 0) {
250 250
 
251
-			if(\count($urlparams) < $params_in_url){
251
+			if (\count($urlparams) < $params_in_url) {
252 252
 				throw new APIClientException('too few URL params, required: '.\implode(', ', $path_elements));
253 253
 			}
254 254
 
255 255
 			$endpoint = \sprintf($endpoint, ...$urlparams);
256 256
 		}
257 257
 
258
-		if(\in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){
258
+		if (\in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) {
259 259
 			$body = $arguments[$params_in_url + 1] ?? $params;
260 260
 
261
-			if($params === $body){
261
+			if ($params === $body) {
262 262
 				$params = [];
263 263
 			}
264 264
 
@@ -308,24 +308,24 @@  discard block
 block discarded – undo
308 308
 		$request = $this->requestFactory
309 309
 			->createRequest($method ?? 'GET', Psr7\merge_query($this->apiURL.$path, $params ?? []));
310 310
 
311
-		foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){
311
+		foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) {
312 312
 			$request = $request->withAddedHeader($header, $value);
313 313
 		}
314 314
 
315
-		if(is_array($body) && $request->hasHeader('content-type')){
315
+		if (is_array($body) && $request->hasHeader('content-type')) {
316 316
 			$contentType = \strtolower($request->getHeaderLine('content-type'));
317 317
 
318 318
 			// @todo: content type support
319
-			if($contentType === 'application/x-www-form-urlencoded'){
319
+			if ($contentType === 'application/x-www-form-urlencoded') {
320 320
 				$body = $this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738));
321 321
 			}
322
-			elseif($contentType === 'application/json'){
322
+			elseif ($contentType === 'application/json') {
323 323
 				$body = $this->streamFactory->createStream(\json_encode($body));
324 324
 			}
325 325
 
326 326
 		}
327 327
 
328
-		if($body instanceof StreamInterface){
328
+		if ($body instanceof StreamInterface) {
329 329
 			$request = $request
330 330
 				->withBody($body)
331 331
 				->withHeader('Content-length', $body->getSize())
@@ -343,11 +343,11 @@  discard block
 block discarded – undo
343 343
 	public function sendRequest(RequestInterface $request):ResponseInterface{
344 344
 
345 345
 		// get authorization only if we request the provider API
346
-		if(\strpos((string)$request->getUri(), $this->apiURL) === 0){
346
+		if (\strpos((string)$request->getUri(), $this->apiURL) === 0) {
347 347
 			$token = $this->storage->getAccessToken($this->serviceName);
348 348
 
349 349
 			// attempt to refresh an expired token
350
-			if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){
350
+			if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) {
351 351
 				$token = $this->refreshAccessToken($token);
352 352
 			}
353 353
 
Please login to merge, or discard this patch.