Passed
Push — master ( 978abe...35535b )
by smiley
01:58
created
src/Core/OAuthProvider.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 *
122 122
 	 * @throws \chillerlan\HTTP\MagicAPI\ApiClientException
123 123
 	 */
124
-	public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options){
124
+	public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options) {
125 125
 		$this->http    = $http;
126 126
 		$this->storage = $storage;
127 127
 		$this->options = $options;
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
 
134 134
 		$this->serviceName = (new ReflectionClass($this))->getShortName();
135 135
 
136
-		if(!empty($this->endpointMap) && class_exists($this->endpointMap)){
136
+		if (!empty($this->endpointMap) && class_exists($this->endpointMap)) {
137 137
 			$this->endpoints = new $this->endpointMap;
138 138
 
139
-			if(!$this->endpoints instanceof EndpointMapInterface){
139
+			if (!$this->endpoints instanceof EndpointMapInterface) {
140 140
 				throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore
141 141
 			}
142 142
 
@@ -149,9 +149,9 @@  discard block
 block discarded – undo
149 149
 	 *
150 150
 	 * @return string|null
151 151
 	 */
152
-	public function __get(string $name):?string{
152
+	public function __get(string $name): ?string{
153 153
 
154
-		if(!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL', 'apiURL'], true)){
154
+		if (!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL', 'apiURL'], true)) {
155 155
 			return null;
156 156
 		}
157 157
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	 */
208 208
 	public function __call(string $name, array $arguments):ResponseInterface{
209 209
 
210
-		if(!$this->endpoints instanceof EndpointMapInterface || !$this->endpoints->__isset($name)){
210
+		if (!$this->endpoints instanceof EndpointMapInterface || !$this->endpoints->__isset($name)) {
211 211
 			throw new ApiClientException('endpoint not found');
212 212
 		}
213 213
 
@@ -220,21 +220,21 @@  discard block
 block discarded – undo
220 220
 		$path_elements = $m['path_elements'] ?? [];
221 221
 		$params_in_url = count($path_elements);
222 222
 		$params        = $arguments[$params_in_url] ?? [];
223
-		$urlparams     = array_slice($arguments,0 , $params_in_url);
223
+		$urlparams     = array_slice($arguments, 0, $params_in_url);
224 224
 
225
-		if($params_in_url > 0){
225
+		if ($params_in_url > 0) {
226 226
 
227
-			if(count($urlparams) < $params_in_url){
227
+			if (count($urlparams) < $params_in_url) {
228 228
 				throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements));
229 229
 			}
230 230
 
231 231
 			$endpoint = sprintf($endpoint, ...$urlparams);
232 232
 		}
233 233
 
234
-		if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){
234
+		if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) {
235 235
 			$body = $arguments[$params_in_url + 1] ?? $params;
236 236
 
237
-			if($params === $body){
237
+			if ($params === $body) {
238 238
 				$params = [];
239 239
 			}
240 240
 
@@ -281,32 +281,32 @@  discard block
 block discarded – undo
281 281
 		$token = $this->storage->getAccessToken($this->serviceName);
282 282
 
283 283
 		// attempt to refresh an expired token
284
-		if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){
284
+		if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) {
285 285
 			$token = $this->refreshAccessToken($token);
286 286
 		}
287 287
 
288 288
 		$request = $this->requestFactory
289 289
 			->createRequest($method ?? 'GET', Psr7\merge_query($this->apiURL.$path, $params ?? []));
290 290
 
291
-		foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){
291
+		foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) {
292 292
 			$request = $request->withAddedHeader($header, $value);
293 293
 		}
294 294
 
295 295
 		$request = $this->getRequestAuthorization($request, $token);
296 296
 
297
-		if(is_array($body) && $request->hasHeader('content-type')){
297
+		if (is_array($body) && $request->hasHeader('content-type')) {
298 298
 			$contentType = strtolower($request->getHeaderLine('content-type'));
299 299
 
300
-			if($contentType === 'application/x-www-form-urlencoded'){
300
+			if ($contentType === 'application/x-www-form-urlencoded') {
301 301
 				$body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738));
302 302
 			}
303
-			elseif($contentType === 'application/json'){
303
+			elseif ($contentType === 'application/json') {
304 304
 				$body = $this->streamFactory->createStream(json_encode($body));
305 305
 			}
306 306
 
307 307
 		}
308 308
 
309
-		if($body instanceof StreamInterface){
309
+		if ($body instanceof StreamInterface) {
310 310
 			$request = $request->withBody($body);
311 311
 		}
312 312
 
Please login to merge, or discard this patch.