Passed
Push — master ( 2bb952...ced49e )
by smiley
01:32
created
src/Core/OAuthProvider.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 *
129 129
 	 * @throws \chillerlan\HTTP\MagicAPI\ApiClientException
130 130
 	 */
131
-	public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null){
131
+	public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null) {
132 132
 		$this->http    = $http;
133 133
 		$this->storage = $storage;
134 134
 		$this->options = $options;
@@ -140,10 +140,10 @@  discard block
 block discarded – undo
140 140
 
141 141
 		$this->serviceName = (new ReflectionClass($this))->getShortName();
142 142
 
143
-		if($this instanceof ApiClientInterface && !empty($this->endpointMap) && \class_exists($this->endpointMap)){
143
+		if ($this instanceof ApiClientInterface && !empty($this->endpointMap) && \class_exists($this->endpointMap)) {
144 144
 			$this->endpoints = new $this->endpointMap;
145 145
 
146
-			if(!$this->endpoints instanceof EndpointMapInterface){
146
+			if (!$this->endpoints instanceof EndpointMapInterface) {
147 147
 				throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore
148 148
 			}
149 149
 
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 	 *
157 157
 	 * @return mixed|null
158 158
 	 */
159
-	public function __get(string $name){
159
+	public function __get(string $name) {
160 160
 
161
-		if(\in_array($name, $this::ALLOWED_PROPERTIES, true)){
161
+		if (\in_array($name, $this::ALLOWED_PROPERTIES, true)) {
162 162
 			return $this->{$name};
163 163
 		}
164 164
 
@@ -215,11 +215,11 @@  discard block
 block discarded – undo
215 215
 	 */
216 216
 	public function __call(string $name, array $arguments):ResponseInterface{
217 217
 
218
-		if(!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap){
218
+		if (!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap) {
219 219
 			throw new ApiClientException('MagicAPI not available');
220 220
 		}
221 221
 
222
-		if(!$this->endpoints->__isset($name)){
222
+		if (!$this->endpoints->__isset($name)) {
223 223
 			throw new ApiClientException('endpoint not found');
224 224
 		}
225 225
 
@@ -232,21 +232,21 @@  discard block
 block discarded – undo
232 232
 		$path_elements = $m['path_elements'] ?? [];
233 233
 		$params_in_url = \count($path_elements);
234 234
 		$params        = $arguments[$params_in_url] ?? [];
235
-		$urlparams     = \array_slice($arguments,0 , $params_in_url);
235
+		$urlparams     = \array_slice($arguments, 0, $params_in_url);
236 236
 
237
-		if($params_in_url > 0){
237
+		if ($params_in_url > 0) {
238 238
 
239
-			if(\count($urlparams) < $params_in_url){
239
+			if (\count($urlparams) < $params_in_url) {
240 240
 				throw new APIClientException('too few URL params, required: '.\implode(', ', $path_elements));
241 241
 			}
242 242
 
243 243
 			$endpoint = \sprintf($endpoint, ...$urlparams);
244 244
 		}
245 245
 
246
-		if(\in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){
246
+		if (\in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) {
247 247
 			$body = $arguments[$params_in_url + 1] ?? $params;
248 248
 
249
-			if($params === $body){
249
+			if ($params === $body) {
250 250
 				$params = [];
251 251
 			}
252 252
 
@@ -296,24 +296,24 @@  discard block
 block discarded – undo
296 296
 		$request = $this->requestFactory
297 297
 			->createRequest($method ?? 'GET', Psr7\merge_query($this->apiURL.$path, $params ?? []));
298 298
 
299
-		foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){
299
+		foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) {
300 300
 			$request = $request->withAddedHeader($header, $value);
301 301
 		}
302 302
 
303
-		if(is_array($body) && $request->hasHeader('content-type')){
303
+		if (is_array($body) && $request->hasHeader('content-type')) {
304 304
 			$contentType = \strtolower($request->getHeaderLine('content-type'));
305 305
 
306 306
 			// @todo: content type support
307
-			if($contentType === 'application/x-www-form-urlencoded'){
307
+			if ($contentType === 'application/x-www-form-urlencoded') {
308 308
 				$body = $this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738));
309 309
 			}
310
-			elseif($contentType === 'application/json'){
310
+			elseif ($contentType === 'application/json') {
311 311
 				$body = $this->streamFactory->createStream(\json_encode($body));
312 312
 			}
313 313
 
314 314
 		}
315 315
 
316
-		if($body instanceof StreamInterface){
316
+		if ($body instanceof StreamInterface) {
317 317
 			$request = $request
318 318
 				->withBody($body)
319 319
 				->withHeader('Content-length', $body->getSize())
@@ -331,11 +331,11 @@  discard block
 block discarded – undo
331 331
 	public function sendRequest(RequestInterface $request):ResponseInterface{
332 332
 
333 333
 		// get authorization only if we request the provider API
334
-		if(\strpos((string)$request->getUri(), $this->apiURL) === 0){
334
+		if (\strpos((string)$request->getUri(), $this->apiURL) === 0) {
335 335
 			$token = $this->storage->getAccessToken($this->serviceName);
336 336
 
337 337
 			// attempt to refresh an expired token
338
-			if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){
338
+			if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) {
339 339
 				$token = $this->refreshAccessToken($token);
340 340
 			}
341 341
 
Please login to merge, or discard this patch.