Completed
Push — master ( 436069...978abe )
by smiley
01:47
created
src/Core/AccessToken.php 2 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -138,11 +138,9 @@
 block discarded – undo
138 138
 
139 139
 		if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){
140 140
 			$this->expires = $this::EOL_NEVER_EXPIRES;
141
-		}
142
-		elseif($expires > $now){
141
+		} elseif($expires > $now){
143 142
 			$this->expires = $expires;
144
-		}
145
-		elseif($expires > 0 && $expires < $this::EXPIRY_MAX){
143
+		} elseif($expires > 0 && $expires < $this::EXPIRY_MAX){
146 144
 			$this->expires = $now + $expires;
147 145
 		}
148 146
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 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);
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	public function __set(string $property, $value):void{
101 101
 
102
-		if(property_exists($this, $property)){
102
+		if (property_exists($this, $property)) {
103 103
 			$property === 'expires'
104 104
 				? $this->setExpiry($value)
105 105
 				: $this->{$property} = $value;
@@ -115,19 +115,19 @@  discard block
 block discarded – undo
115 115
 	public function setExpiry(int $expires = null):AccessToken{
116 116
 		$now = time();
117 117
 
118
-		if($expires!== null){
119
-			$expires =  intval($expires);
118
+		if ($expires !== null) {
119
+			$expires = intval($expires);
120 120
 		}
121 121
 
122 122
 		$this->expires = $this::EOL_UNKNOWN;
123 123
 
124
-		if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){
124
+		if ($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES) {
125 125
 			$this->expires = $this::EOL_NEVER_EXPIRES;
126 126
 		}
127
-		elseif($expires > $now){
127
+		elseif ($expires > $now) {
128 128
 			$this->expires = $expires;
129 129
 		}
130
-		elseif($expires > 0 && $expires < $this::EXPIRY_MAX){
130
+		elseif ($expires > 0 && $expires < $this::EXPIRY_MAX) {
131 131
 			$this->expires = $now + $expires;
132 132
 		}
133 133
 
Please login to merge, or discard this patch.
src/Storage/OAuthStorageException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,4 +14,4 @@
 block discarded – undo
14 14
 
15 15
 use chillerlan\OAuth\OAuthException;
16 16
 
17
-class OAuthStorageException extends OAuthException{}
17
+class OAuthStorageException extends OAuthException {}
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]); // trigger the memzero destructor
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.
src/Storage/SessionStorage.php 2 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -83,8 +83,7 @@  discard block
 block discarded – undo
83 83
 
84 84
 		if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){
85 85
 			$_SESSION[$this->sessionVar][$service] = $token;
86
-		}
87
-		else{
86
+		} else{
88 87
 			$_SESSION[$this->sessionVar] = [$service => $token];
89 88
 		}
90 89
 
@@ -153,8 +152,7 @@  discard block
 block discarded – undo
153 152
 
154 153
 		if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){
155 154
 			$_SESSION[$this->stateVar][$service] = $state;
156
-		}
157
-		else{
155
+		} else{
158 156
 			$_SESSION[$this->stateVar] = [$service => $state];
159 157
 		}
160 158
 
Please login to merge, or discard this 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 bool
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @param \chillerlan\Settings\SettingsContainerInterface|null $options
39 39
 	 */
40
-	public function __construct(SettingsContainerInterface $options = null){
40
+	public function __construct(SettingsContainerInterface $options = null) {
41 41
 		parent::__construct($options);
42 42
 
43 43
 		$this->sessionVar = $this->options->sessionTokenVar;
@@ -45,15 +45,15 @@  discard block
 block discarded – undo
45 45
 
46 46
 		// Determine if the session has started.
47 47
 		// @link http://stackoverflow.com/a/18542272/1470961
48
-		if($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)){
48
+		if ($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)) {
49 49
 			session_start();
50 50
 		}
51 51
 
52
-		if(!isset($_SESSION[$this->sessionVar])){
52
+		if (!isset($_SESSION[$this->sessionVar])) {
53 53
 			$_SESSION[$this->sessionVar] = [];
54 54
 		}
55 55
 
56
-		if(!isset($_SESSION[$this->stateVar])){
56
+		if (!isset($_SESSION[$this->stateVar])) {
57 57
 			$_SESSION[$this->stateVar] = [];
58 58
 		}
59 59
 
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
 	 *
65 65
 	 * @codeCoverageIgnore
66 66
 	 */
67
-	public function __destruct(){
68
-		if($this->options->sessionStart){
67
+	public function __destruct() {
68
+		if ($this->options->sessionStart) {
69 69
 			session_write_close();
70 70
 		}
71 71
 	}
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
 	public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{
80 80
 		$token = $token->toJSON();
81 81
 
82
-		if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){
82
+		if (isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])) {
83 83
 			$_SESSION[$this->sessionVar][$service] = $token;
84 84
 		}
85
-		else{
85
+		else {
86 86
 			$_SESSION[$this->sessionVar] = [$service => $token];
87 87
 		}
88 88
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	 */
98 98
 	public function getAccessToken(string $service):AccessToken{
99 99
 
100
-		if($this->hasAccessToken($service)){
100
+		if ($this->hasAccessToken($service)) {
101 101
 			return (new AccessToken)->fromJSON($_SESSION[$this->sessionVar][$service]);
102 102
 		}
103 103
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	 */
121 121
 	public function clearAccessToken(string $service):OAuthStorageInterface{
122 122
 
123
-		if(array_key_exists($service, $_SESSION[$this->sessionVar])){
123
+		if (array_key_exists($service, $_SESSION[$this->sessionVar])) {
124 124
 			unset($_SESSION[$this->sessionVar][$service]);
125 125
 		}
126 126
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 */
133 133
 	public function clearAllAccessTokens():OAuthStorageInterface{
134 134
 
135
-		foreach(array_keys($_SESSION[$this->sessionVar]) as $service){
135
+		foreach (array_keys($_SESSION[$this->sessionVar]) as $service) {
136 136
 			unset($_SESSION[$this->sessionVar][$service]); // trigger the memzero destructor
137 137
 		}
138 138
 
@@ -149,10 +149,10 @@  discard block
 block discarded – undo
149 149
 	 */
150 150
 	public function storeCSRFState(string $service, string $state):OAuthStorageInterface{
151 151
 
152
-		if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){
152
+		if (isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])) {
153 153
 			$_SESSION[$this->stateVar][$service] = $state;
154 154
 		}
155
-		else{
155
+		else {
156 156
 			$_SESSION[$this->stateVar] = [$service => $state];
157 157
 		}
158 158
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	 */
168 168
 	public function getCSRFState(string $service):string{
169 169
 
170
-		if($this->hasCSRFState($service)){
170
+		if ($this->hasCSRFState($service)) {
171 171
 			return $_SESSION[$this->stateVar][$service];
172 172
 		}
173 173
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	 */
191 191
 	public function clearCSRFState(string $service):OAuthStorageInterface{
192 192
 
193
-		if(array_key_exists($service, $_SESSION[$this->stateVar])){
193
+		if (array_key_exists($service, $_SESSION[$this->stateVar])) {
194 194
 			unset($_SESSION[$this->stateVar][$service]);
195 195
 		}
196 196
 
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
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 
15 15
 use chillerlan\OAuth\Core\AccessToken;
16 16
 
17
-interface OAuthStorageInterface{
17
+interface OAuthStorageInterface {
18 18
 
19 19
 	public const TOKEN_NONCE = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01";
20 20
 
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
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
 ];
36 36
 
37 37
 /** @var \chillerlan\Settings\SettingsContainerInterface $options */
38
-$options = new class($options_arr) extends OAuthOptions{
38
+$options = new class($options_arr) extends OAuthOptions {
39 39
 	use LogOptionsTrait;
40 40
 
41 41
 	protected $sleep;
Please login to merge, or discard this patch.
src/Core/OAuth2Provider.php 2 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -161,13 +161,11 @@
 block discarded – undo
161 161
 
162 162
 		if(array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)){
163 163
 			$request = $request->withHeader('Authorization', $this::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken);
164
-		}
165
-		elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){
164
+		} elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){
166 165
 			$uri = Psr7\merge_query((string)$request->getUri(), [$this::AUTH_METHODS_QUERY[$this->authMethod] => $token->accessToken]);
167 166
 
168 167
 			$request = $request->withUri($this->uriFactory->createUri($uri));
169
-		}
170
-		else{
168
+		} else{
171 169
 			throw new ProviderException('invalid auth type');
172 170
 		}
173 171
 
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  * @method array setState(array $params)
21 21
  * @method \chillerlan\OAuth\Core\OAuth2Interface checkState(string $state = null)
22 22
  */
23
-abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{
23
+abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface {
24 24
 
25 25
 	/**
26 26
 	 * @var int
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	public function getAuthURL(array $params = null, array $scopes = null):UriInterface{
57 57
 		$params = $params ?? [];
58 58
 
59
-		if(isset($params['client_secret'])){
59
+		if (isset($params['client_secret'])) {
60 60
 			unset($params['client_secret']);
61 61
 		}
62 62
 
@@ -67,11 +67,11 @@  discard block
 block discarded – undo
67 67
 			'type'          => 'web_server',
68 68
 		]);
69 69
 
70
-		if($scopes !== null){
70
+		if ($scopes !== null) {
71 71
 			$params['scope'] = implode($this->scopesDelimiter, $scopes);
72 72
 		}
73 73
 
74
-		if($this instanceof CSRFToken){
74
+		if ($this instanceof CSRFToken) {
75 75
 			$params = $this->setState($params);
76 76
 		}
77 77
 
@@ -87,19 +87,19 @@  discard block
 block discarded – undo
87 87
 	protected function parseTokenResponse(ResponseInterface $response):AccessToken{
88 88
 		$data = json_decode($response->getBody()->getContents(), true);
89 89
 
90
-		if(!is_array($data)){
90
+		if (!is_array($data)) {
91 91
 			throw new ProviderException('unable to parse token response');
92 92
 		}
93 93
 
94
-		foreach(['error_description', 'error'] as $field){
94
+		foreach (['error_description', 'error'] as $field) {
95 95
 
96
-			if(isset($data[$field])){
96
+			if (isset($data[$field])) {
97 97
 				throw new ProviderException('error retrieving access token: "'.$data[$field].'"');
98 98
 			}
99 99
 
100 100
 		}
101 101
 
102
-		if(!isset($data['access_token'])){
102
+		if (!isset($data['access_token'])) {
103 103
 			throw new ProviderException('token missing');
104 104
 		}
105 105
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function getAccessToken(string $code, string $state = null):AccessToken{
127 127
 
128
-		if($this instanceof CSRFToken){
128
+		if ($this instanceof CSRFToken) {
129 129
 			$this->checkState($state);
130 130
 		}
131 131
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 			->withHeader('Content-Type', 'application/x-www-form-urlencoded')
143 143
 			->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)));
144 144
 
145
-		foreach($this->authHeaders as $header => $value){
145
+		foreach ($this->authHeaders as $header => $value) {
146 146
 			$request = $request->withHeader($header, $value);
147 147
 		}
148 148
 
@@ -162,15 +162,15 @@  discard block
 block discarded – undo
162 162
 	 */
163 163
 	public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{
164 164
 
165
-		if(array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)){
165
+		if (array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)) {
166 166
 			$request = $request->withHeader('Authorization', $this::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken);
167 167
 		}
168
-		elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){
168
+		elseif (array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)) {
169 169
 			$uri = Psr7\merge_query((string)$request->getUri(), [$this::AUTH_METHODS_QUERY[$this->authMethod] => $token->accessToken]);
170 170
 
171 171
 			$request = $request->withUri($this->uriFactory->createUri($uri));
172 172
 		}
173
-		else{
173
+		else {
174 174
 			throw new ProviderException('invalid auth type');
175 175
 		}
176 176
 
Please login to merge, or discard this patch.
src/Core/OAuth2TokenRefreshTrait.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
  * @property \Psr\Http\Message\RequestFactoryInterface       $requestFactory
25 25
  * @property \Psr\Http\Message\StreamFactoryInterface        $streamFactory
26 26
  */
27
-trait OAuth2TokenRefreshTrait{
27
+trait OAuth2TokenRefreshTrait {
28 28
 
29 29
 	/**
30 30
 	 * @param \chillerlan\OAuth\Core\AccessToken $token
@@ -34,15 +34,15 @@  discard block
 block discarded – undo
34 34
 	 */
35 35
 	public function refreshAccessToken(AccessToken $token = null):AccessToken{
36 36
 
37
-		if($token === null){
37
+		if ($token === null) {
38 38
 			$token = $this->storage->getAccessToken($this->serviceName);
39 39
 		}
40 40
 
41 41
 		$refreshToken = $token->refreshToken;
42 42
 
43
-		if(empty($refreshToken)){
43
+		if (empty($refreshToken)) {
44 44
 
45
-			if(!$this instanceof AccessTokenForRefresh){
45
+			if (!$this instanceof AccessTokenForRefresh) {
46 46
 				throw new ProviderException(sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires)));
47 47
 			}
48 48
 
@@ -63,13 +63,13 @@  discard block
 block discarded – undo
63 63
 			->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)))
64 64
 		;
65 65
 
66
-		foreach($this->authHeaders as $header => $value){
66
+		foreach ($this->authHeaders as $header => $value) {
67 67
 			$request = $request->withAddedHeader($header, $value);
68 68
 		}
69 69
 
70 70
 		$newToken = $this->parseTokenResponse($this->http->sendRequest($request));
71 71
 
72
-		if(empty($newToken->refreshToken)){
72
+		if (empty($newToken->refreshToken)) {
73 73
 			$newToken->refreshToken = $refreshToken;
74 74
 		}
75 75
 
Please login to merge, or discard this patch.
src/Core/OAuth2CSRFTokenTrait.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  * @property string                                          $serviceName
19 19
  * @property \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
20 20
  */
21
-trait OAuth2CSRFTokenTrait{
21
+trait OAuth2CSRFTokenTrait {
22 22
 
23 23
 	/**
24 24
 	 * @param string|null $state
@@ -28,13 +28,13 @@  discard block
 block discarded – undo
28 28
 	 */
29 29
 	protected function checkState(string $state = null):OAuth2Interface{
30 30
 
31
-		if(empty($state) || !$this->storage->hasCSRFState($this->serviceName)){
31
+		if (empty($state) || !$this->storage->hasCSRFState($this->serviceName)) {
32 32
 			throw new ProviderException('invalid state for '.$this->serviceName);
33 33
 		}
34 34
 
35 35
 		$knownState = $this->storage->getCSRFState($this->serviceName);
36 36
 
37
-		if(!hash_equals($knownState, $state)){
37
+		if (!hash_equals($knownState, $state)) {
38 38
 			throw new ProviderException('invalid CSRF state: '.$this->serviceName.' '.$state);
39 39
 		}
40 40
 
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	 */
50 50
 	protected function setState(array $params):array{
51 51
 
52
-		if(!isset($params['state'])){
52
+		if (!isset($params['state'])) {
53 53
 			$params['state'] = sha1(random_bytes(256));
54 54
 		}
55 55
 
Please login to merge, or discard this patch.