Passed
Push — master ( 475ac1...96c7a7 )
by smiley
01:37
created
src/Core/ClientCredentials.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 
13 13
 namespace chillerlan\OAuth\Core;
14 14
 
15
-interface ClientCredentials{
15
+interface ClientCredentials {
16 16
 
17 17
 	/**
18 18
 	 * Obtains an OAuth2 client credentials token and returns an AccessToken
Please login to merge, or discard this patch.
src/Storage/OAuthStorageInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
15 15
 use chillerlan\OAuth\Core\AccessToken;
16 16
 use Psr\Log\LoggerAwareInterface;
17 17
 
18
-interface OAuthStorageInterface extends LoggerAwareInterface{
18
+interface OAuthStorageInterface extends LoggerAwareInterface {
19 19
 
20 20
 	/**
21 21
 	 * Stores an AccessToken for the given $service
Please login to merge, or discard this patch.
src/Storage/OAuthStorageAbstract.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 
19 19
 use function is_string;
20 20
 
21
-abstract class OAuthStorageAbstract implements OAuthStorageInterface{
21
+abstract class OAuthStorageAbstract implements OAuthStorageInterface {
22 22
 	use LoggerAwareTrait;
23 23
 
24 24
 	/**
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 * @param \chillerlan\Settings\SettingsContainerInterface|null $options
33 33
 	 * @param \Psr\Log\LoggerInterface|null                        $logger
34 34
 	 */
35
-	public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){
35
+	public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) {
36 36
 		$this->options = $options ?? new OAuthOptions;
37 37
 
38 38
 		$this->setLogger($logger ?? new NullLogger);
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 */
55 55
 	public function fromStorage($data):AccessToken{
56 56
 
57
-		if(!is_string($data)){
57
+		if (!is_string($data)) {
58 58
 			throw new OAuthStorageException('invalid data');
59 59
 		}
60 60
 
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
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
 use function array_keys, array_key_exists;
18 18
 
19
-class MemoryStorage extends OAuthStorageAbstract{
19
+class MemoryStorage extends OAuthStorageAbstract {
20 20
 
21 21
 	/**
22 22
 	 * @var array
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	public function getAccessToken(string $service):AccessToken{
44 44
 
45
-		if($this->hasAccessToken($service)){
45
+		if ($this->hasAccessToken($service)) {
46 46
 			return $this->tokens[$service];
47 47
 		}
48 48
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	public function clearAccessToken(string $service):bool{
63 63
 
64
-		if(array_key_exists($service, $this->tokens)){
64
+		if (array_key_exists($service, $this->tokens)) {
65 65
 			unset($this->tokens[$service]);
66 66
 		}
67 67
 
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 */
74 74
 	public function clearAllAccessTokens():bool{
75 75
 
76
-		foreach(array_keys($this->tokens) as $service){
76
+		foreach (array_keys($this->tokens) as $service) {
77 77
 			unset($this->tokens[$service]);
78 78
 		}
79 79
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 */
97 97
 	public function getCSRFState(string $service):string{
98 98
 
99
-		if($this->hasCSRFState($service)){
99
+		if ($this->hasCSRFState($service)) {
100 100
 			return $this->states[$service];
101 101
 		}
102 102
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 */
116 116
 	public function clearCSRFState(string $service):bool{
117 117
 
118
-		if(array_key_exists($service, $this->states)){
118
+		if (array_key_exists($service, $this->states)) {
119 119
 			unset($this->states[$service]);
120 120
 		}
121 121
 
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
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 
20 20
 use const PHP_SESSION_NONE;
21 21
 
22
-class SessionStorage extends OAuthStorageAbstract{
22
+class SessionStorage extends OAuthStorageAbstract {
23 23
 
24 24
 	/**
25 25
 	 * @var string
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 *
37 37
 	 * @param \chillerlan\Settings\SettingsContainerInterface|null $options
38 38
 	 */
39
-	public function __construct(SettingsContainerInterface $options = null){
39
+	public function __construct(SettingsContainerInterface $options = null) {
40 40
 		parent::__construct($options);
41 41
 
42 42
 		$this->sessionVar = $this->options->sessionTokenVar;
@@ -44,15 +44,15 @@  discard block
 block discarded – undo
44 44
 
45 45
 		// Determine if the session has started.
46 46
 		// @link http://stackoverflow.com/a/18542272/1470961
47
-		if($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)){
47
+		if ($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)) {
48 48
 			session_start();
49 49
 		}
50 50
 
51
-		if(!isset($_SESSION[$this->sessionVar])){
51
+		if (!isset($_SESSION[$this->sessionVar])) {
52 52
 			$_SESSION[$this->sessionVar] = [];
53 53
 		}
54 54
 
55
-		if(!isset($_SESSION[$this->stateVar])){
55
+		if (!isset($_SESSION[$this->stateVar])) {
56 56
 			$_SESSION[$this->stateVar] = [];
57 57
 		}
58 58
 
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 	 *
64 64
 	 * @codeCoverageIgnore
65 65
 	 */
66
-	public function __destruct(){
67
-		if($this->options->sessionStart){
66
+	public function __destruct() {
67
+		if ($this->options->sessionStart) {
68 68
 			session_write_close();
69 69
 		}
70 70
 	}
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 */
84 84
 	public function getAccessToken(string $service):AccessToken{
85 85
 
86
-		if($this->hasAccessToken($service)){
86
+		if ($this->hasAccessToken($service)) {
87 87
 			return $this->fromStorage($_SESSION[$this->sessionVar][$service]);
88 88
 		}
89 89
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 */
103 103
 	public function clearAccessToken(string $service):bool{
104 104
 
105
-		if(array_key_exists($service, $_SESSION[$this->sessionVar])){
105
+		if (array_key_exists($service, $_SESSION[$this->sessionVar])) {
106 106
 			unset($_SESSION[$this->sessionVar][$service]);
107 107
 		}
108 108
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 */
115 115
 	public function clearAllAccessTokens():bool{
116 116
 
117
-		foreach(array_keys($_SESSION[$this->sessionVar]) as $service){
117
+		foreach (array_keys($_SESSION[$this->sessionVar]) as $service) {
118 118
 			unset($_SESSION[$this->sessionVar][$service]);
119 119
 		}
120 120
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	 */
138 138
 	public function getCSRFState(string $service):string{
139 139
 
140
-		if($this->hasCSRFState($service)){
140
+		if ($this->hasCSRFState($service)) {
141 141
 			return $_SESSION[$this->stateVar][$service];
142 142
 		}
143 143
 
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 	 */
157 157
 	public function clearCSRFState(string $service):bool{
158 158
 
159
-		if(array_key_exists($service, $_SESSION[$this->stateVar])){
159
+		if (array_key_exists($service, $_SESSION[$this->stateVar])) {
160 160
 			unset($_SESSION[$this->stateVar][$service]);
161 161
 		}
162 162
 
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 AUTH_METHOD_HEADER = 1;
20 20
 	const AUTH_METHOD_QUERY  = 2;
Please login to merge, or discard this patch.
src/Core/OAuth2Provider.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 use const PHP_QUERY_RFC1738;
24 24
 
25
-abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{
25
+abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface {
26 26
 
27 27
 	/**
28 28
 	 * @var int
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	public function getAuthURL(array $params = null, array $scopes = null):UriInterface{
61 61
 		$params = $params ?? [];
62 62
 
63
-		if(isset($params['client_secret'])){
63
+		if (isset($params['client_secret'])) {
64 64
 			unset($params['client_secret']);
65 65
 		}
66 66
 
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
 			'type'          => 'web_server',
72 72
 		]);
73 73
 
74
-		if(!empty($scopes)){
74
+		if (!empty($scopes)) {
75 75
 			$params['scope'] = implode($this->scopesDelimiter, $scopes);
76 76
 		}
77 77
 
78
-		if($this instanceof CSRFToken){
78
+		if ($this instanceof CSRFToken) {
79 79
 			$params = $this->setState($params);
80 80
 		}
81 81
 
@@ -91,19 +91,19 @@  discard block
 block discarded – undo
91 91
 	protected function parseTokenResponse(ResponseInterface $response):AccessToken{
92 92
 		$data = json_decode(decompress_content($response), true); // silly amazon...
93 93
 
94
-		if(!is_array($data)){
94
+		if (!is_array($data)) {
95 95
 			throw new ProviderException('unable to parse token response');
96 96
 		}
97 97
 
98
-		foreach(['error_description', 'error'] as $field){
98
+		foreach (['error_description', 'error'] as $field) {
99 99
 
100
-			if(isset($data[$field])){
100
+			if (isset($data[$field])) {
101 101
 				throw new ProviderException('error retrieving access token: "'.$data[$field].'"');
102 102
 			}
103 103
 
104 104
 		}
105 105
 
106
-		if(!isset($data['access_token'])){
106
+		if (!isset($data['access_token'])) {
107 107
 			throw new ProviderException('token missing');
108 108
 		}
109 109
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	 */
127 127
 	public function getAccessToken(string $code, string $state = null):AccessToken{
128 128
 
129
-		if($this instanceof CSRFToken){
129
+		if ($this instanceof CSRFToken) {
130 130
 			$this->checkState($state);
131 131
 		}
132 132
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 			->withHeader('Accept-Encoding', 'identity')
145 145
 			->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)));
146 146
 
147
-		foreach($this->authHeaders as $header => $value){
147
+		foreach ($this->authHeaders as $header => $value) {
148 148
 			$request = $request->withHeader($header, $value);
149 149
 		}
150 150
 
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
 	 */
161 161
 	public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{
162 162
 
163
-		if($this->authMethod === OAuth2Interface::AUTH_METHOD_HEADER){
163
+		if ($this->authMethod === OAuth2Interface::AUTH_METHOD_HEADER) {
164 164
 			return $request->withHeader('Authorization', $this->authMethodHeader.' '.$token->accessToken);
165 165
 		}
166 166
 
167
-		if($this->authMethod === OAuth2Interface::AUTH_METHOD_QUERY){
167
+		if ($this->authMethod === OAuth2Interface::AUTH_METHOD_QUERY) {
168 168
 			$uri = merge_query($request->getUri()->__toString(), [$this->authMethodQuery => $token->accessToken]);
169 169
 
170 170
 			return $request->withUri($this->uriFactory->createUri($uri));
@@ -179,13 +179,13 @@  discard block
 block discarded – undo
179 179
 	 */
180 180
 	public function getClientCredentialsToken(array $scopes = null):AccessToken{
181 181
 
182
-		if(!$this instanceof ClientCredentials){
182
+		if (!$this instanceof ClientCredentials) {
183 183
 			throw new ProviderException('client credentials token not supported');
184 184
 		}
185 185
 
186 186
 		$params = ['grant_type' => 'client_credentials'];
187 187
 
188
-		if($scopes !== null){
188
+		if ($scopes !== null) {
189 189
 			$params['scope'] = implode($this->scopesDelimiter, $scopes);
190 190
 		}
191 191
 
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 			->withBody($this->streamFactory->createStream(http_build_query($params, '', '&', PHP_QUERY_RFC1738)))
198 198
 		;
199 199
 
200
-		foreach($this->authHeaders as $header => $value){
200
+		foreach ($this->authHeaders as $header => $value) {
201 201
 			$request = $request->withAddedHeader($header, $value);
202 202
 		}
203 203
 
@@ -214,17 +214,17 @@  discard block
 block discarded – undo
214 214
 	 */
215 215
 	public function refreshAccessToken(AccessToken $token = null):AccessToken{
216 216
 
217
-		if(!$this instanceof TokenRefresh){
217
+		if (!$this instanceof TokenRefresh) {
218 218
 			throw new ProviderException('token refresh not supported');
219 219
 		}
220 220
 
221
-		if($token === null){
221
+		if ($token === null) {
222 222
 			$token = $this->storage->getAccessToken($this->serviceName);
223 223
 		}
224 224
 
225 225
 		$refreshToken = $token->refreshToken;
226 226
 
227
-		if(empty($refreshToken)){
227
+		if (empty($refreshToken)) {
228 228
 			throw new ProviderException(
229 229
 				sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires))
230 230
 			);
@@ -245,13 +245,13 @@  discard block
 block discarded – undo
245 245
 			->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)))
246 246
 		;
247 247
 
248
-		foreach($this->authHeaders as $header => $value){
248
+		foreach ($this->authHeaders as $header => $value) {
249 249
 			$request = $request->withAddedHeader($header, $value);
250 250
 		}
251 251
 
252 252
 		$newToken = $this->parseTokenResponse($this->http->sendRequest($request));
253 253
 
254
-		if(empty($newToken->refreshToken)){
254
+		if (empty($newToken->refreshToken)) {
255 255
 			$newToken->refreshToken = $refreshToken;
256 256
 		}
257 257
 
@@ -268,13 +268,13 @@  discard block
 block discarded – undo
268 268
 	 */
269 269
 	protected function checkState(string $state = null):void{
270 270
 
271
-		if(empty($state) || !$this->storage->hasCSRFState($this->serviceName)){
271
+		if (empty($state) || !$this->storage->hasCSRFState($this->serviceName)) {
272 272
 			throw new ProviderException('invalid state for '.$this->serviceName);
273 273
 		}
274 274
 
275 275
 		$knownState = $this->storage->getCSRFState($this->serviceName);
276 276
 
277
-		if(!hash_equals($knownState, $state)){
277
+		if (!hash_equals($knownState, $state)) {
278 278
 			throw new ProviderException('invalid CSRF state: '.$this->serviceName.' '.$state);
279 279
 		}
280 280
 
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 	 */
288 288
 	protected function setState(array $params):array{
289 289
 
290
-		if(!isset($params['state'])){
290
+		if (!isset($params['state'])) {
291 291
 			$params['state'] = sha1(random_bytes(256));
292 292
 		}
293 293
 
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
@@ -40,6 +40,6 @@
 block discarded – undo
40 40
  * @property int        $retries
41 41
  * @property array      $curl_multi_options
42 42
  */
43
-class OAuthOptions extends SettingsContainerAbstract{
43
+class OAuthOptions extends SettingsContainerAbstract {
44 44
 	use OAuthOptionsTrait, HTTPOptionsTrait;
45 45
 }
Please login to merge, or discard this patch.