Completed
Push — master ( 76b2bf...a8e198 )
by smiley
02:16
created
examples/OAuth1Testprovider.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 
15 15
 use chillerlan\OAuth\Core\OAuth1Provider;
16 16
 
17
-class OAuth1Testprovider extends OAuth1Provider{
17
+class OAuth1Testprovider extends OAuth1Provider {
18 18
 
19 19
 	protected $apiURL          = 'https://api.example.com';
20 20
 	protected $requestTokenURL = 'https://example.com/oauth/request_token';
Please login to merge, or discard this patch.
examples/TestEndpoints.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 
15 15
 use chillerlan\HTTP\MagicAPI\EndpointMap;
16 16
 
17
-class TestEndpoints extends EndpointMap{
17
+class TestEndpoints extends EndpointMap {
18 18
 
19 19
 	protected $test = [
20 20
 		'path'          => '/test/%1$s',
Please login to merge, or discard this patch.
examples/OAuth2Testprovider.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 	protected $authURL        = 'https://example.com/oauth2/authorize';
25 25
 	protected $accessTokenURL = 'https://example.com/oauth2/token';
26 26
 	protected $userRevokeURL  = 'https://account.example.com/apps/';
27
-	protected $endpointMap     = TestEndpoints::class;
27
+	protected $endpointMap = TestEndpoints::class;
28 28
 	protected $authHeaders    = ['foo' => 'bar'];
29 29
 	protected $apiHeaders     = ['foo' => 'bar'];
30 30
 
Please login to merge, or discard this patch.
src/Core/OAuth2Interface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 
15 15
 use Psr\Http\Message\UriInterface;
16 16
 
17
-interface OAuth2Interface extends OAuthInterface{
17
+interface OAuth2Interface extends OAuthInterface {
18 18
 
19 19
 	const HEADER_OAUTH              = 0;
20 20
 	const HEADER_BEARER             = 1;
Please login to merge, or discard this patch.
src/OAuthOptions.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,6 +36,6 @@
 block discarded – undo
36 36
  * @property bool       $ssl_verifypeer
37 37
  * @property string     $curlHandle
38 38
  */
39
-class OAuthOptions extends SettingsContainerAbstract{
39
+class OAuthOptions extends SettingsContainerAbstract {
40 40
 	use OAuthOptionsTrait, HTTPOptionsTrait;
41 41
 }
Please login to merge, or discard this patch.
src/Core/AccessToken.php 2 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -123,11 +123,9 @@
 block discarded – undo
123 123
 
124 124
 		if($expires === 0 || $expires === self::EOL_NEVER_EXPIRES){
125 125
 			$this->expires = self::EOL_NEVER_EXPIRES;
126
-		}
127
-		elseif($expires > $now){
126
+		} elseif($expires > $now){
128 127
 			$this->expires = $expires;
129
-		}
130
-		elseif($expires > 0 && $expires < self::EXPIRY_MAX){
128
+		} elseif($expires > 0 && $expires < self::EXPIRY_MAX){
131 129
 			$this->expires = $now + $expires;
132 130
 		}
133 131
 
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
  * @property int    $expires
30 30
  * @property string $provider
31 31
  */
32
-class AccessToken extends SettingsContainerAbstract{
32
+class AccessToken extends SettingsContainerAbstract {
33 33
 
34 34
 	/**
35 35
 	 * Denotes an unknown end of life time.
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 *
84 84
 	 * @param iterable|null $properties
85 85
 	 */
86
-	public function __construct(iterable $properties = null){
86
+	public function __construct(iterable $properties = null) {
87 87
 		parent::__construct($properties);
88 88
 
89 89
 		$this->setExpiry($this->expires);
@@ -108,19 +108,19 @@  discard block
 block discarded – undo
108 108
 	public function setExpiry(int $expires = null):AccessToken{
109 109
 		$now = \time();
110 110
 
111
-		if($expires!== null){
111
+		if ($expires !== null) {
112 112
 			$expires = \intval($expires);
113 113
 		}
114 114
 
115 115
 		$this->expires = self::EOL_UNKNOWN;
116 116
 
117
-		if($expires === 0 || $expires === self::EOL_NEVER_EXPIRES){
117
+		if ($expires === 0 || $expires === self::EOL_NEVER_EXPIRES) {
118 118
 			$this->expires = self::EOL_NEVER_EXPIRES;
119 119
 		}
120
-		elseif($expires > $now){
120
+		elseif ($expires > $now) {
121 121
 			$this->expires = $expires;
122 122
 		}
123
-		elseif($expires > 0 && $expires < self::EXPIRY_MAX){
123
+		elseif ($expires > 0 && $expires < self::EXPIRY_MAX) {
124 124
 			$this->expires = $now + $expires;
125 125
 		}
126 126
 
Please login to merge, or discard this patch.
src/Storage/OAuthStorageAbstract.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 	 * @param \chillerlan\Settings\SettingsContainerInterface|null $options
31 31
 	 * @param \Psr\Log\LoggerInterface|null                        $logger
32 32
 	 */
33
-	public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){
33
+	public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) {
34 34
 		$this->options = $options ?? new OAuthOptions;
35 35
 
36 36
 		$this->setLogger($logger ?? new NullLogger);
Please login to merge, or discard this patch.
examples/oauth-example-common.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
 ];
35 35
 
36 36
 /** @var \chillerlan\Settings\SettingsContainerInterface $options */
37
-$options = new class($options_arr) extends OAuthOptions{
37
+$options = new class($options_arr) extends OAuthOptions {
38 38
 	protected $sleep; // testHTTPClient
39 39
 };
40 40
 
Please login to merge, or discard this patch.
src/Core/OAuthProvider.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -306,8 +306,7 @@
 block discarded – undo
306 306
 			// @todo: content type support
307 307
 			if($contentType === 'application/x-www-form-urlencoded'){
308 308
 				$body = $this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738));
309
-			}
310
-			elseif($contentType === 'application/json'){
309
+			} elseif($contentType === 'application/json'){
311 310
 				$body = $this->streamFactory->createStream(\json_encode($body));
312 311
 			}
313 312
 
Please login to merge, or discard this 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.