Completed
Push — master ( 74df5b...18ae99 )
by smiley
04:02
created
src/Core/OAuthProvider.php 1 patch
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 $this->{$name};
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 || !$this->endpoints instanceof EndpointMap){
212
+		if (!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap) {
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
-		foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){
293
+		foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) {
294 294
 			$request = $request->withAddedHeader($header, $value);
295 295
 		}
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 300
 			// @todo: content type support
301
-			if($contentType === 'application/x-www-form-urlencoded'){
301
+			if ($contentType === 'application/x-www-form-urlencoded') {
302 302
 				$body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738));
303 303
 			}
304
-			elseif($contentType === 'application/json'){
304
+			elseif ($contentType === 'application/json') {
305 305
 				$body = $this->streamFactory->createStream(json_encode($body));
306 306
 			}
307 307
 
308 308
 		}
309 309
 
310
-		if($body instanceof StreamInterface){
310
+		if ($body instanceof StreamInterface) {
311 311
 			$request = $request
312 312
 				->withBody($body)
313 313
 				->withHeader('Content-length', $body->getSize())
@@ -325,11 +325,11 @@  discard block
 block discarded – undo
325 325
 	public function sendRequest(RequestInterface $request):ResponseInterface{
326 326
 
327 327
 		// get authorization only if we request the provider API
328
-		if(strpos((string)$request->getUri(), $this->apiURL) === 0){
328
+		if (strpos((string)$request->getUri(), $this->apiURL) === 0) {
329 329
 			$token = $this->storage->getAccessToken($this->serviceName);
330 330
 
331 331
 			// attempt to refresh an expired token
332
-			if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){
332
+			if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) {
333 333
 				$token = $this->refreshAccessToken($token);
334 334
 			}
335 335
 
Please login to merge, or discard this patch.
src/Core/OAuth1Provider.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 use DateTime;
19 19
 use Psr\Http\Message\{RequestInterface, ResponseInterface, UriInterface};
20 20
 
21
-abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface{
21
+abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface {
22 22
 
23 23
 	/**
24 24
 	 * @var string
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 			->withHeader('Accept-Encoding', 'identity')
63 63
 		;
64 64
 
65
-		foreach($this->authHeaders as $header => $value){
65
+		foreach ($this->authHeaders as $header => $value) {
66 66
 			$request = $request->withAddedHeader($header, $value);
67 67
 		}
68 68
 
@@ -79,17 +79,17 @@  discard block
 block discarded – undo
79 79
 	protected function parseTokenResponse(ResponseInterface $response, bool $checkCallbackConfirmed = null):AccessToken{
80 80
 		parse_str(Psr7\decompress_content($response), $data);
81 81
 
82
-		if(!$data || !is_array($data)){
82
+		if (!$data || !is_array($data)) {
83 83
 			throw new ProviderException('unable to parse token response');
84 84
 		}
85
-		elseif(isset($data['error'])){
85
+		elseif (isset($data['error'])) {
86 86
 			throw new ProviderException('error retrieving access token: '.$data['error']);
87 87
 		}
88
-		elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){
88
+		elseif (!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])) {
89 89
 			throw new ProviderException('invalid token');
90 90
 		}
91 91
 
92
-		if($checkCallbackConfirmed && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true')){
92
+		if ($checkCallbackConfirmed && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true')) {
93 93
 			throw new ProviderException('oauth callback unconfirmed');
94 94
 		}
95 95
 
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 	protected function getSignature(string $url, array $params, string $method, string $accessTokenSecret = null):string{
136 136
 		$parseURL = parse_url($url);
137 137
 
138
-		if(!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)){
138
+		if (!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)) {
139 139
 			throw new ProviderException('getSignature: invalid url');
140 140
 		}
141 141
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 
144 144
 		$signatureParams = array_merge($query, $params);
145 145
 
146
-		if(isset($signatureParams['oauth_signature'])){
146
+		if (isset($signatureParams['oauth_signature'])) {
147 147
 			unset($signatureParams['oauth_signature']);
148 148
 		}
149 149
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 			$token->accessTokenSecret
202 202
 		);
203 203
 
204
-		if(isset($query['oauth_session_handle'])){
204
+		if (isset($query['oauth_session_handle'])) {
205 205
 			$parameters['oauth_session_handle'] = $query['oauth_session_handle']; // @codeCoverageIgnore
206 206
 		}
207 207
 
Please login to merge, or discard this patch.
src/Core/AccessToken.php 1 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/SessionStorage.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 use chillerlan\OAuth\Core\AccessToken;
16 16
 use chillerlan\Settings\SettingsContainerInterface;
17 17
 
18
-class SessionStorage extends OAuthStorageAbstract{
18
+class SessionStorage extends OAuthStorageAbstract {
19 19
 
20 20
 	/**
21 21
 	 * @var string
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @param \chillerlan\Settings\SettingsContainerInterface|null $options
34 34
 	 */
35
-	public function __construct(SettingsContainerInterface $options = null){
35
+	public function __construct(SettingsContainerInterface $options = null) {
36 36
 		parent::__construct($options);
37 37
 
38 38
 		$this->sessionVar = $this->options->sessionTokenVar;
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
 
41 41
 		// Determine if the session has started.
42 42
 		// @link http://stackoverflow.com/a/18542272/1470961
43
-		if($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)){
43
+		if ($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)) {
44 44
 			session_start();
45 45
 		}
46 46
 
47
-		if(!isset($_SESSION[$this->sessionVar])){
47
+		if (!isset($_SESSION[$this->sessionVar])) {
48 48
 			$_SESSION[$this->sessionVar] = [];
49 49
 		}
50 50
 
51
-		if(!isset($_SESSION[$this->stateVar])){
51
+		if (!isset($_SESSION[$this->stateVar])) {
52 52
 			$_SESSION[$this->stateVar] = [];
53 53
 		}
54 54
 
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @codeCoverageIgnore
61 61
 	 */
62
-	public function __destruct(){
63
-		if($this->options->sessionStart){
62
+	public function __destruct() {
63
+		if ($this->options->sessionStart) {
64 64
 			session_write_close();
65 65
 		}
66 66
 	}
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
 	public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{
75 75
 		$token = $token->toJSON();
76 76
 
77
-		if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){
77
+		if (isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])) {
78 78
 			$_SESSION[$this->sessionVar][$service] = $token;
79 79
 		}
80
-		else{
80
+		else {
81 81
 			$_SESSION[$this->sessionVar] = [$service => $token];
82 82
 		}
83 83
 
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 */
93 93
 	public function getAccessToken(string $service):AccessToken{
94 94
 
95
-		if($this->hasAccessToken($service)){
95
+		if ($this->hasAccessToken($service)) {
96 96
 			return (new AccessToken)->fromJSON($_SESSION[$this->sessionVar][$service]);
97 97
 		}
98 98
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 */
116 116
 	public function clearAccessToken(string $service):OAuthStorageInterface{
117 117
 
118
-		if(array_key_exists($service, $_SESSION[$this->sessionVar])){
118
+		if (array_key_exists($service, $_SESSION[$this->sessionVar])) {
119 119
 			unset($_SESSION[$this->sessionVar][$service]);
120 120
 		}
121 121
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 	 */
128 128
 	public function clearAllAccessTokens():OAuthStorageInterface{
129 129
 
130
-		foreach(array_keys($_SESSION[$this->sessionVar]) as $service){
130
+		foreach (array_keys($_SESSION[$this->sessionVar]) as $service) {
131 131
 			unset($_SESSION[$this->sessionVar][$service]);
132 132
 		}
133 133
 
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
 	 */
145 145
 	public function storeCSRFState(string $service, string $state):OAuthStorageInterface{
146 146
 
147
-		if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){
147
+		if (isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])) {
148 148
 			$_SESSION[$this->stateVar][$service] = $state;
149 149
 		}
150
-		else{
150
+		else {
151 151
 			$_SESSION[$this->stateVar] = [$service => $state];
152 152
 		}
153 153
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	 */
163 163
 	public function getCSRFState(string $service):string{
164 164
 
165
-		if($this->hasCSRFState($service)){
165
+		if ($this->hasCSRFState($service)) {
166 166
 			return $_SESSION[$this->stateVar][$service];
167 167
 		}
168 168
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	 */
186 186
 	public function clearCSRFState(string $service):OAuthStorageInterface{
187 187
 
188
-		if(array_key_exists($service, $_SESSION[$this->stateVar])){
188
+		if (array_key_exists($service, $_SESSION[$this->stateVar])) {
189 189
 			unset($_SESSION[$this->stateVar][$service]);
190 190
 		}
191 191
 
Please login to merge, or discard this patch.
src/Storage/MemoryStorage.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 
15 15
 use chillerlan\OAuth\Core\AccessToken;
16 16
 
17
-class MemoryStorage extends OAuthStorageAbstract{
17
+class MemoryStorage extends OAuthStorageAbstract {
18 18
 
19 19
 	/**
20 20
 	 * @var array
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 */
47 47
 	public function getAccessToken(string $service):AccessToken{
48 48
 
49
-		if($this->hasAccessToken($service)){
49
+		if ($this->hasAccessToken($service)) {
50 50
 			return $this->tokens[$service];
51 51
 		}
52 52
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public function clearAccessToken(string $service):OAuthStorageInterface{
71 71
 
72
-		if(array_key_exists($service, $this->tokens)){
72
+		if (array_key_exists($service, $this->tokens)) {
73 73
 			unset($this->tokens[$service]);
74 74
 		}
75 75
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 */
82 82
 	public function clearAllAccessTokens():OAuthStorageInterface{
83 83
 
84
-		foreach(array_keys($this->tokens) as $service){
84
+		foreach (array_keys($this->tokens) as $service) {
85 85
 			unset($this->tokens[$service]);
86 86
 		}
87 87
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 */
111 111
 	public function getCSRFState(string $service):string{
112 112
 
113
-		if($this->hasCSRFState($service)){
113
+		if ($this->hasCSRFState($service)) {
114 114
 			return $this->states[$service];
115 115
 		}
116 116
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	 */
134 134
 	public function clearCSRFState(string $service):OAuthStorageInterface{
135 135
 
136
-		if(array_key_exists($service, $this->states)){
136
+		if (array_key_exists($service, $this->states)) {
137 137
 			unset($this->states[$service]);
138 138
 		}
139 139
 
Please login to merge, or discard this patch.