Completed
Push — master ( 71b37f...ce8319 )
by smiley
03:13 queued 01:04
created
src/OAuthOptionsTrait.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
 namespace chillerlan\OAuth;
14 14
 
15
-trait OAuthOptionsTrait{
15
+trait OAuthOptionsTrait {
16 16
 
17 17
 	/**
18 18
 	 * @var string
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	/**
77 77
 	 * @var string
78 78
 	 */
79
-	protected $dbLabelFormat   = '%1$s@%2$s'; // user@service
79
+	protected $dbLabelFormat = '%1$s@%2$s'; // user@service
80 80
 
81 81
 	/**
82 82
 	 * @var int|string
Please login to merge, or discard this patch.
src/Storage/TokenStorageInterface.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\Token;
16 16
 
17
-interface TokenStorageInterface{
17
+interface TokenStorageInterface {
18 18
 
19 19
 	/**
20 20
 	 * @param string                  $service
Please login to merge, or discard this patch.
src/Storage/TokenStorageException.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 TokenStorageException extends OAuthException{}
17
+class TokenStorageException extends OAuthException {}
Please login to merge, or discard this patch.
src/Storage/SessionTokenStorage.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
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
  *      - the session is running through a session handler that already encrypts the session data. nothing to do here.
22 22
  *      - the session runs in memory - i think it's silly to encrypt there. sodium_memzero() galore!
23 23
  */
24
-class SessionTokenStorage extends TokenStorageAbstract{
24
+class SessionTokenStorage extends TokenStorageAbstract {
25 25
 
26 26
 	/**
27 27
 	 * @var bool
@@ -43,21 +43,21 @@  discard block
 block discarded – undo
43 43
 	 *
44 44
 	 * @param \chillerlan\Traits\ContainerInterface|null $options
45 45
 	 */
46
-	public function __construct(ContainerInterface $options = null){
46
+	public function __construct(ContainerInterface $options = null) {
47 47
 		parent::__construct($options);
48 48
 
49 49
 		$this->sessionVar = $this->options->sessionTokenVar;
50 50
 		$this->stateVar = $this->options->sessionStateVar;
51 51
 
52
-		if($this->options->sessionStart && !$this->sessionIsActive()){
52
+		if ($this->options->sessionStart && !$this->sessionIsActive()) {
53 53
 			session_start();
54 54
 		}
55 55
 
56
-		if(!isset($_SESSION[$this->sessionVar])){
56
+		if (!isset($_SESSION[$this->sessionVar])) {
57 57
 			$_SESSION[$this->sessionVar] = [];
58 58
 		}
59 59
 
60
-		if(!isset($_SESSION[$this->stateVar])){
60
+		if (!isset($_SESSION[$this->stateVar])) {
61 61
 			$_SESSION[$this->stateVar] = [];
62 62
 		}
63 63
 
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 	/**
67 67
 	 * Destructor.
68 68
 	 */
69
-	public function __destruct(){
70
-		if($this->options->sessionStart){
69
+	public function __destruct() {
70
+		if ($this->options->sessionStart) {
71 71
 			session_write_close();
72 72
 		}
73 73
 	}
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
 	public function storeAccessToken(string $service, Token $token):TokenStorageInterface{
82 82
 		$token = $token->__toJSON();
83 83
 
84
-		if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){
84
+		if (isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])) {
85 85
 			$_SESSION[$this->sessionVar][$service] = $token;
86 86
 		}
87
-		else{
87
+		else {
88 88
 			$_SESSION[$this->sessionVar] = [$service => $token];
89 89
 		}
90 90
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	public function getAccessToken(string $service):Token{
101 101
 
102
-		if($this->hasAccessToken($service)){
102
+		if ($this->hasAccessToken($service)) {
103 103
 			return (new Token)->__fromJSON($_SESSION[$this->sessionVar][$service]);
104 104
 		}
105 105
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function clearAccessToken(string $service):TokenStorageInterface{
124 124
 
125
-		if(array_key_exists($service, $_SESSION[$this->sessionVar])){
125
+		if (array_key_exists($service, $_SESSION[$this->sessionVar])) {
126 126
 			unset($_SESSION[$this->sessionVar][$service]);
127 127
 		}
128 128
 
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 */
135 135
 	public function clearAllAccessTokens():TokenStorageInterface{
136 136
 
137
-		foreach(array_keys($_SESSION[$this->sessionVar]) as $service){
137
+		foreach (array_keys($_SESSION[$this->sessionVar]) as $service) {
138 138
 			unset($_SESSION[$this->sessionVar][$service]); // trigger the memzero destructor
139 139
 		}
140 140
 
@@ -151,10 +151,10 @@  discard block
 block discarded – undo
151 151
 	 */
152 152
 	public function storeCSRFState(string $service, string $state):TokenStorageInterface{
153 153
 
154
-		if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){
154
+		if (isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])) {
155 155
 			$_SESSION[$this->stateVar][$service] = $state;
156 156
 		}
157
-		else{
157
+		else {
158 158
 			$_SESSION[$this->stateVar] = [$service => $state];
159 159
 		}
160 160
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	 */
170 170
 	public function getCSRFState(string $service):string{
171 171
 
172
-		if($this->hasCSRFState($service)){
172
+		if ($this->hasCSRFState($service)) {
173 173
 			return $_SESSION[$this->stateVar][$service];
174 174
 		}
175 175
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	 */
193 193
 	public function clearCSRFState(string $service):TokenStorageInterface{
194 194
 
195
-		if(array_key_exists($service, $_SESSION[$this->stateVar])){
195
+		if (array_key_exists($service, $_SESSION[$this->stateVar])) {
196 196
 			unset($_SESSION[$this->stateVar][$service]);
197 197
 		}
198 198
 
Please login to merge, or discard this patch.
src/Storage/TokenStorageAbstract.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @param \chillerlan\Traits\ContainerInterface|null $options
34 34
 	 */
35
-	public function __construct(ContainerInterface $options = null){
35
+	public function __construct(ContainerInterface $options = null) {
36 36
 		$this->options = $options ?? new OAuthOptions;
37 37
 	}
38 38
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
 		unset($token);
48 48
 
49
-		if($this->options->useEncryption === true){
49
+		if ($this->options->useEncryption === true) {
50 50
 			return $this->encrypt($data);
51 51
 		}
52 52
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 */
61 61
 	public function fromStorage(string $data):Token{
62 62
 
63
-		if($this->options->useEncryption === true){
63
+		if ($this->options->useEncryption === true) {
64 64
 			$data = $this->decrypt($data);
65 65
 		}
66 66
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 */
76 76
 	protected function encrypt(string &$data):string {
77 77
 
78
-		if(function_exists('sodium_crypto_secretbox')){
78
+		if (function_exists('sodium_crypto_secretbox')) {
79 79
 			$box = sodium_crypto_secretbox($data, $this::TOKEN_NONCE, sodium_hex2bin($this->options->storageCryptoKey));
80 80
 
81 81
 			sodium_memzero($data);
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 */
95 95
 	protected function decrypt(string $box):string {
96 96
 
97
-		if(function_exists('sodium_crypto_secretbox_open')){
97
+		if (function_exists('sodium_crypto_secretbox_open')) {
98 98
 			return sodium_crypto_secretbox_open(sodium_hex2bin($box), $this::TOKEN_NONCE, sodium_hex2bin($this->options->storageCryptoKey));
99 99
 		}
100 100
 
Please login to merge, or discard this patch.
src/OAuthException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,4 +12,4 @@
 block discarded – undo
12 12
 
13 13
 namespace chillerlan\OAuth;
14 14
 
15
-class OAuthException extends \Exception{}
15
+class OAuthException extends \Exception {}
Please login to merge, or discard this patch.
src/Token.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
  * @property int    $expires
32 32
  * @property string $provider
33 33
  */
34
-class Token implements ContainerInterface{
34
+class Token implements ContainerInterface {
35 35
 	use MemzeroDestructorTrait, Container{
36 36
 		__construct as constructContainer;
37 37
 	}
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 *
99 99
 	 * @param array|null $properties
100 100
 	 */
101
-	public function __construct(array $properties = null){
101
+	public function __construct(array $properties = null) {
102 102
 		$this->constructContainer($properties);
103 103
 
104 104
 		$this->setExpiry($this->expires);
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 	 *
113 113
 	 * @return void
114 114
 	 */
115
-	public function __set(string $property, $value){
115
+	public function __set(string $property, $value) {
116 116
 
117
-		if(property_exists($this, $property)){
117
+		if (property_exists($this, $property)) {
118 118
 			$property === 'expires'
119 119
 				? $this->setExpiry($value)
120 120
 				: $this->{$property} = $value;
@@ -130,19 +130,19 @@  discard block
 block discarded – undo
130 130
 	public function setExpiry(int $expires = null):Token{
131 131
 		$now = time();
132 132
 
133
-		if($expires!== null){
134
-			$expires =  intval($expires);
133
+		if ($expires !== null) {
134
+			$expires = intval($expires);
135 135
 		}
136 136
 
137 137
 		$this->expires = $this::EOL_UNKNOWN;
138 138
 
139
-		if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){
139
+		if ($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES) {
140 140
 			$this->expires = $this::EOL_NEVER_EXPIRES;
141 141
 		}
142
-		elseif($expires > $now){
142
+		elseif ($expires > $now) {
143 143
 			$this->expires = $expires;
144 144
 		}
145
-		elseif($expires > 0 && $expires < $this::EXPIRY_MAX){
145
+		elseif ($expires > 0 && $expires < $this::EXPIRY_MAX) {
146 146
 			$this->expires = $now + $expires;
147 147
 		}
148 148
 
Please login to merge, or discard this patch.
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.
src/OAuthOptions.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
  * @property string     $ca_info
56 56
  * @property int        $max_redirects
57 57
  */
58
-class OAuthOptions implements ContainerInterface{
58
+class OAuthOptions implements ContainerInterface {
59 59
 	use OAuthOptionsTrait, HTTPOptionsTrait, MemzeroDestructorTrait, Container{
60 60
 		__construct as protected containerConstruct;
61 61
 	}
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 *
66 66
 	 * @param array|null $properties
67 67
 	 */
68
-	public function __construct(array $properties = null){
68
+	public function __construct(array $properties = null) {
69 69
 		// enable encryption by default if possible...
70 70
 		$this->useEncryption = extension_loaded('sodium');
71 71
 
Please login to merge, or discard this patch.
src/Providers/OAuth2Provider.php 2 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -216,11 +216,9 @@
 block discarded – undo
216 216
 			$headers = array_merge($headers, [
217 217
 				'Authorization' => $this::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken,
218 218
 			]);
219
-		}
220
-		elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){
219
+		} elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){
221 220
 			$params[$this::AUTH_METHODS_QUERY[$this->authMethod]] = $token->accessToken;
222
-		}
223
-		else{
221
+		} else{
224 222
 			throw new ProviderException('invalid auth type');
225 223
 		}
226 224
 
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  * @method array setState(array $params)
26 26
  * @method \chillerlan\OAuth\Providers\OAuth2Interface checkState(string $state = null)
27 27
  */
28
-abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{
28
+abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface {
29 29
 
30 30
 	/**
31 31
 	 * @var int
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * @param \chillerlan\Traits\ContainerInterface           $options
61 61
 	 * @param array                                           $scopes
62 62
 	 */
63
-	public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options, array $scopes = null){
63
+	public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options, array $scopes = null) {
64 64
 		parent::__construct($http, $storage, $options);
65 65
 
66 66
 		$this->scopes = $scopes ?? [];
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	public function getAuthURL(array $params = null):string{
75 75
 		$params = $this->getAuthURLParams($params ?? []);
76 76
 
77
-		if($this instanceof CSRFToken){
77
+		if ($this instanceof CSRFToken) {
78 78
 			$params = $this->setState($params);
79 79
 		}
80 80
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	protected function getAuthURLParams(array $params):array {
90 90
 
91 91
 		// this should not be here
92
-		if(isset($params['client_secret'])){
92
+		if (isset($params['client_secret'])) {
93 93
 			unset($params['client_secret']);
94 94
 		}
95 95
 
@@ -111,19 +111,19 @@  discard block
 block discarded – undo
111 111
 	protected function parseTokenResponse(HTTPResponseInterface $response):Token{
112 112
 		$data = $response->json_array;
113 113
 
114
-		if(!is_array($data)){
114
+		if (!is_array($data)) {
115 115
 			throw new ProviderException('unable to parse token response');
116 116
 		}
117 117
 
118
-		foreach(['error_description', 'error'] as $field){
118
+		foreach (['error_description', 'error'] as $field) {
119 119
 
120
-			if(isset($data[$field])){
120
+			if (isset($data[$field])) {
121 121
 				throw new ProviderException('error retrieving access token: "'.$data[$field].'"');
122 122
 			}
123 123
 
124 124
 		}
125 125
 
126
-		if(!isset($data['access_token'])){
126
+		if (!isset($data['access_token'])) {
127 127
 			throw new ProviderException('token missing');
128 128
 		}
129 129
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 */
150 150
 	public function getAccessToken(string $code, string $state = null):Token{
151 151
 
152
-		if($this instanceof CSRFToken){
152
+		if ($this instanceof CSRFToken) {
153 153
 			$this->checkState($state);
154 154
 		}
155 155
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 		$token = $this->storage->getAccessToken($this->serviceName);
204 204
 
205 205
 		// attempt to refresh an expired token
206
-		if($this->options->tokenAutoRefresh && $this instanceof TokenRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){
206
+		if ($this->options->tokenAutoRefresh && $this instanceof TokenRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) {
207 207
 			$token = $this->refreshAccessToken($token);
208 208
 		}
209 209
 
@@ -212,15 +212,15 @@  discard block
 block discarded – undo
212 212
 		$params  = array_merge($query, $params ?? []);
213 213
 		$headers = $headers ?? [];
214 214
 
215
-		if(array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)){
215
+		if (array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)) {
216 216
 			$headers = array_merge($headers, [
217 217
 				'Authorization' => $this::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken,
218 218
 			]);
219 219
 		}
220
-		elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){
220
+		elseif (array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)) {
221 221
 			$params[$this::AUTH_METHODS_QUERY[$this->authMethod]] = $token->accessToken;
222 222
 		}
223
-		else{
223
+		else {
224 224
 			throw new ProviderException('invalid auth type');
225 225
 		}
226 226
 
Please login to merge, or discard this patch.