Passed
Push — main ( 0b4281...d8887d )
by smiley
12:51
created
src/Storage/MemoryStorage.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 /**
18 18
  * Implements a memory storage adapter. Memory storage is not persistent as tokens are only stored during script runtime.
19 19
  */
20
-class MemoryStorage extends OAuthStorageAbstract{
20
+class MemoryStorage extends OAuthStorageAbstract {
21 21
 
22 22
 	/**
23 23
 	 * the token storage array
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 */
44 44
 	public function getAccessToken(string $service):AccessToken{
45 45
 
46
-		if($this->hasAccessToken($service)){
46
+		if ($this->hasAccessToken($service)) {
47 47
 			return $this->tokens[$service];
48 48
 		}
49 49
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	public function clearAccessToken(string $service):OAuthStorageInterface{
64 64
 
65
-		if(array_key_exists($service, $this->tokens)){
65
+		if (array_key_exists($service, $this->tokens)) {
66 66
 			unset($this->tokens[$service]);
67 67
 		}
68 68
 
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	 */
75 75
 	public function clearAllAccessTokens():OAuthStorageInterface{
76 76
 
77
-		foreach(array_keys($this->tokens) as $service){
77
+		foreach (array_keys($this->tokens) as $service) {
78 78
 			unset($this->tokens[$service]);
79 79
 		}
80 80
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	 */
98 98
 	public function getCSRFState(string $service):string{
99 99
 
100
-		if($this->hasCSRFState($service)){
100
+		if ($this->hasCSRFState($service)) {
101 101
 			return $this->states[$service];
102 102
 		}
103 103
 
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	 */
117 117
 	public function clearCSRFState(string $service):OAuthStorageInterface{
118 118
 
119
-		if(array_key_exists($service, $this->states)){
119
+		if (array_key_exists($service, $this->states)) {
120 120
 			unset($this->states[$service]);
121 121
 		}
122 122
 
Please login to merge, or discard this patch.
src/Storage/SessionStorage.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 /**
21 21
  * Implements a session storage adapter. Session storage is half persistent as tokens are stored for the duration of the session.
22 22
  */
23
-class SessionStorage extends OAuthStorageAbstract{
23
+class SessionStorage extends OAuthStorageAbstract {
24 24
 
25 25
 	/**
26 26
 	 * the key name for the token storage array in $_SESSION
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	/**
36 36
 	 * SessionStorage constructor.
37 37
 	 */
38
-	public function __construct(SettingsContainerInterface $options = null){
38
+	public function __construct(SettingsContainerInterface $options = null) {
39 39
 		parent::__construct($options);
40 40
 
41 41
 		$this->tokenVar = $this->options->sessionTokenVar;
@@ -43,15 +43,15 @@  discard block
 block discarded – undo
43 43
 
44 44
 		// Determine if the session has started.
45 45
 		// @link http://stackoverflow.com/a/18542272/1470961
46
-		if($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)){
46
+		if ($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)) {
47 47
 			session_start();
48 48
 		}
49 49
 
50
-		if(!isset($_SESSION[$this->tokenVar])){
50
+		if (!isset($_SESSION[$this->tokenVar])) {
51 51
 			$_SESSION[$this->tokenVar] = [];
52 52
 		}
53 53
 
54
-		if(!isset($_SESSION[$this->stateVar])){
54
+		if (!isset($_SESSION[$this->stateVar])) {
55 55
 			$_SESSION[$this->stateVar] = [];
56 56
 		}
57 57
 
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 *
63 63
 	 * @codeCoverageIgnore
64 64
 	 */
65
-	public function __destruct(){
66
-		if($this->options->sessionStart){
65
+	public function __destruct() {
66
+		if ($this->options->sessionStart) {
67 67
 			session_write_close();
68 68
 		}
69 69
 	}
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	 */
83 83
 	public function getAccessToken(string $service):AccessToken{
84 84
 
85
-		if($this->hasAccessToken($service)){
85
+		if ($this->hasAccessToken($service)) {
86 86
 			return $this->fromStorage($_SESSION[$this->tokenVar][$service]);
87 87
 		}
88 88
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	 */
102 102
 	public function clearAccessToken(string $service):OAuthStorageInterface{
103 103
 
104
-		if(array_key_exists($service, $_SESSION[$this->tokenVar])){
104
+		if (array_key_exists($service, $_SESSION[$this->tokenVar])) {
105 105
 			unset($_SESSION[$this->tokenVar][$service]);
106 106
 		}
107 107
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	public function clearAllAccessTokens():OAuthStorageInterface{
115 115
 
116
-		foreach(array_keys($_SESSION[$this->tokenVar]) as $service){
116
+		foreach (array_keys($_SESSION[$this->tokenVar]) as $service) {
117 117
 			unset($_SESSION[$this->tokenVar][$service]);
118 118
 		}
119 119
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 	 */
137 137
 	public function getCSRFState(string $service):string{
138 138
 
139
-		if($this->hasCSRFState($service)){
139
+		if ($this->hasCSRFState($service)) {
140 140
 			return $_SESSION[$this->stateVar][$service];
141 141
 		}
142 142
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 */
156 156
 	public function clearCSRFState(string $service):OAuthStorageInterface{
157 157
 
158
-		if(array_key_exists($service, $_SESSION[$this->stateVar])){
158
+		if (array_key_exists($service, $_SESSION[$this->stateVar])) {
159 159
 			unset($_SESSION[$this->stateVar][$service]);
160 160
 		}
161 161
 
Please login to merge, or discard this patch.
src/Core/OAuth2Provider.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  * Implements an abstract OAuth2 provider with all methods required by the OAuth2Interface.
27 27
  * It also implements the ClientCredentials, CSRFToken and TokenRefresh interfaces in favor over traits.
28 28
  */
29
-abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{
29
+abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface {
30 30
 
31 31
 	/**
32 32
 	 * Specifies the authentication method:
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 			'type'          => 'web_server',
84 84
 		]);
85 85
 
86
-		if(!empty($scopes)){
86
+		if (!empty($scopes)) {
87 87
 			$params['scope'] = implode($this->scopesDelimiter, $scopes);
88 88
 		}
89 89
 
90
-		if($this instanceof CSRFToken){
90
+		if ($this instanceof CSRFToken) {
91 91
 			$params = $this->setState($params);
92 92
 		}
93 93
 
@@ -106,19 +106,19 @@  discard block
 block discarded – undo
106 106
 		// silly amazon sends compressed data...
107 107
 		$data = json_decode(MessageUtil::decompress($response), true, 512, JSON_THROW_ON_ERROR);
108 108
 
109
-		if(!is_array($data)){
109
+		if (!is_array($data)) {
110 110
 			throw new ProviderException('unable to parse token response');
111 111
 		}
112 112
 
113
-		foreach(['error_description', 'error'] as $field){
113
+		foreach (['error_description', 'error'] as $field) {
114 114
 
115
-			if(isset($data[$field])){
115
+			if (isset($data[$field])) {
116 116
 				throw new ProviderException('error retrieving access token: "'.$data[$field].'"');
117 117
 			}
118 118
 
119 119
 		}
120 120
 
121
-		if(!isset($data['access_token'])){
121
+		if (!isset($data['access_token'])) {
122 122
 			throw new ProviderException('token missing');
123 123
 		}
124 124
 
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	 */
141 141
 	public function getAccessToken(string $code, string $state = null):AccessToken{
142 142
 
143
-		if($this instanceof CSRFToken){
143
+		if ($this instanceof CSRFToken) {
144 144
 			$this->checkState($state);
145 145
 		}
146 146
 
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 			->withHeader('Accept-Encoding', 'identity')
159 159
 			->withBody($this->streamFactory->createStream($this->buildQuery($body, PHP_QUERY_RFC1738)));
160 160
 
161
-		foreach($this->authHeaders as $header => $value){
161
+		foreach ($this->authHeaders as $header => $value) {
162 162
 			$request = $request->withHeader($header, $value);
163 163
 		}
164 164
 
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
 	 */
175 175
 	public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{
176 176
 
177
-		if($this->authMethod === OAuth2Interface::AUTH_METHOD_HEADER){
177
+		if ($this->authMethod === OAuth2Interface::AUTH_METHOD_HEADER) {
178 178
 			return $request->withHeader('Authorization', $this->authMethodHeader.' '.$token->accessToken);
179 179
 		}
180 180
 
181
-		if($this->authMethod === OAuth2Interface::AUTH_METHOD_QUERY){
181
+		if ($this->authMethod === OAuth2Interface::AUTH_METHOD_QUERY) {
182 182
 			$uri = $this->mergeQuery((string)$request->getUri(), [$this->authMethodQuery => $token->accessToken]);
183 183
 
184 184
 			return $request->withUri($this->uriFactory->createUri($uri));
@@ -196,13 +196,13 @@  discard block
 block discarded – undo
196 196
 	 */
197 197
 	public function getClientCredentialsToken(array $scopes = null):AccessToken{
198 198
 
199
-		if(!$this instanceof ClientCredentials){
199
+		if (!$this instanceof ClientCredentials) {
200 200
 			throw new ProviderException('client credentials token not supported');
201 201
 		}
202 202
 
203 203
 		$params = ['grant_type' => 'client_credentials'];
204 204
 
205
-		if($scopes !== null){
205
+		if ($scopes !== null) {
206 206
 			$params['scope'] = implode($this->scopesDelimiter, $scopes);
207 207
 		}
208 208
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 			->withBody($this->streamFactory->createStream($this->buildQuery($params, PHP_QUERY_RFC1738)))
215 215
 		;
216 216
 
217
-		foreach($this->authHeaders as $header => $value){
217
+		foreach ($this->authHeaders as $header => $value) {
218 218
 			$request = $request->withAddedHeader($header, $value);
219 219
 		}
220 220
 
@@ -234,17 +234,17 @@  discard block
 block discarded – undo
234 234
 	 */
235 235
 	public function refreshAccessToken(AccessToken $token = null):AccessToken{
236 236
 
237
-		if(!$this instanceof TokenRefresh){
237
+		if (!$this instanceof TokenRefresh) {
238 238
 			throw new ProviderException('token refresh not supported');
239 239
 		}
240 240
 
241
-		if($token === null){
241
+		if ($token === null) {
242 242
 			$token = $this->storage->getAccessToken($this->serviceName);
243 243
 		}
244 244
 
245 245
 		$refreshToken = $token->refreshToken;
246 246
 
247
-		if(empty($refreshToken)){
247
+		if (empty($refreshToken)) {
248 248
 			throw new ProviderException(
249 249
 				sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires))
250 250
 			);
@@ -265,13 +265,13 @@  discard block
 block discarded – undo
265 265
 			->withBody($this->streamFactory->createStream($this->buildQuery($body, PHP_QUERY_RFC1738)))
266 266
 		;
267 267
 
268
-		foreach($this->authHeaders as $header => $value){
268
+		foreach ($this->authHeaders as $header => $value) {
269 269
 			$request = $request->withAddedHeader($header, $value);
270 270
 		}
271 271
 
272 272
 		$newToken = $this->parseTokenResponse($this->http->sendRequest($request));
273 273
 
274
-		if(empty($newToken->refreshToken)){
274
+		if (empty($newToken->refreshToken)) {
275 275
 			$newToken->refreshToken = $refreshToken;
276 276
 		}
277 277
 
@@ -291,17 +291,17 @@  discard block
 block discarded – undo
291 291
 	 */
292 292
 	public function checkState(string $state = null):void{
293 293
 
294
-		if(!$this instanceof CSRFToken){
294
+		if (!$this instanceof CSRFToken) {
295 295
 			throw new ProviderException('CSRF protection not supported');
296 296
 		}
297 297
 
298
-		if(empty($state) || !$this->storage->hasCSRFState($this->serviceName)){
298
+		if (empty($state) || !$this->storage->hasCSRFState($this->serviceName)) {
299 299
 			throw new ProviderException('invalid state for '.$this->serviceName);
300 300
 		}
301 301
 
302 302
 		$knownState = $this->storage->getCSRFState($this->serviceName);
303 303
 
304
-		if(!hash_equals($knownState, $state)){
304
+		if (!hash_equals($knownState, $state)) {
305 305
 			throw new ProviderException('invalid CSRF state: '.$this->serviceName.' '.$state);
306 306
 		}
307 307
 
@@ -318,11 +318,11 @@  discard block
 block discarded – undo
318 318
 	 */
319 319
 	public function setState(array $params):array{
320 320
 
321
-		if(!$this instanceof CSRFToken){
321
+		if (!$this instanceof CSRFToken) {
322 322
 			throw new ProviderException('CSRF protection not supported');
323 323
 		}
324 324
 
325
-		if(!isset($params['state'])){
325
+		if (!isset($params['state'])) {
326 326
 			$params['state'] = sha1(random_bytes(256));
327 327
 		}
328 328
 
Please login to merge, or discard this patch.