Passed
Push — master ( 674dd2...67765b )
by smiley
01:55
created
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 ImmutableSettingsInterface{
58
+class OAuthOptions implements ImmutableSettingsInterface {
59 59
 	use OAuthOptionsTrait, HTTPOptionsTrait, MemzeroDestructorTrait, ImmutableSettingsContainer{
60 60
 		__construct as protected containerConstruct;
61 61
 	}
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 *
66 66
 	 * @param iterable|null $properties
67 67
 	 */
68
-	public function __construct(iterable $properties = null){
68
+	public function __construct(iterable $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/Core/AccessToken.php 1 patch
Spacing   +8 added lines, -8 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 AccessToken implements ImmutableSettingsInterface{
34
+class AccessToken implements ImmutableSettingsInterface {
35 35
 	use MemzeroDestructorTrait, ImmutableSettingsContainer{
36 36
 		__construct as constructContainer;
37 37
 	}
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 *
99 99
 	 * @param iterable|null $properties
100 100
 	 */
101
-	public function __construct(iterable $properties = null){
101
+	public function __construct(iterable $properties = null) {
102 102
 		$this->constructContainer($properties);
103 103
 
104 104
 		$this->setExpiry($this->expires);
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 */
115 115
 	public function __set(string $property, $value):void{
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):AccessToken{
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.
src/Core/OAuthProvider.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 * @param \chillerlan\Traits\ImmutableSettingsInterface           $options
91 91
 	 * @param \Psr\Log\LoggerInterface|null                   $logger
92 92
 	 */
93
-	public function __construct(HTTPClientInterface $http, OAuthStorageInterface $storage, ImmutableSettingsInterface $options, LoggerInterface $logger = null){
93
+	public function __construct(HTTPClientInterface $http, OAuthStorageInterface $storage, ImmutableSettingsInterface $options, LoggerInterface $logger = null) {
94 94
 		$this->setHTTPClient($http);
95 95
 
96 96
 		$this->storage     = $storage;
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 
100 100
 		$this->serviceName = (new ReflectionClass($this))->getShortName();
101 101
 
102
-		if($this instanceof ApiClientInterface){
102
+		if ($this instanceof ApiClientInterface) {
103 103
 			$this->loadEndpoints();
104 104
 		}
105 105
 
Please login to merge, or discard this patch.
src/Core/OAuth2Provider.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  * @method array setState(array $params)
27 27
  * @method \chillerlan\OAuth\Core\OAuth2Interface checkState(string $state = null)
28 28
  */
29
-abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{
29
+abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface {
30 30
 
31 31
 	/**
32 32
 	 * @var int
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
 	 * @param \Psr\Log\LoggerInterface|null                   $logger
63 63
 	 * @param array                                           $scopes
64 64
 	 */
65
-	public function __construct(HTTPClientInterface $http, OAuthStorageInterface $storage, ImmutableSettingsInterface $options, LoggerInterface $logger = null, array $scopes = null){
65
+	public function __construct(HTTPClientInterface $http, OAuthStorageInterface $storage, ImmutableSettingsInterface $options, LoggerInterface $logger = null, array $scopes = null) {
66 66
 		parent::__construct($http, $storage, $options, $logger);
67 67
 
68
-		if($scopes !== null){
68
+		if ($scopes !== null) {
69 69
 			$this->scopes = $scopes;
70 70
 		}
71 71
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	public function getAuthURL(array $params = null):string{
80 80
 		$params = $this->getAuthURLParams($params ?? []);
81 81
 
82
-		if($this instanceof CSRFToken){
82
+		if ($this instanceof CSRFToken) {
83 83
 			$params = $this->setState($params);
84 84
 		}
85 85
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	protected function getAuthURLParams(array $params):array {
95 95
 
96 96
 		// this should not be here
97
-		if(isset($params['client_secret'])){
97
+		if (isset($params['client_secret'])) {
98 98
 			unset($params['client_secret']);
99 99
 		}
100 100
 
@@ -116,19 +116,19 @@  discard block
 block discarded – undo
116 116
 	protected function parseTokenResponse(HTTPResponseInterface $response):AccessToken{
117 117
 		$data = $response->json_array;
118 118
 
119
-		if(!is_array($data)){
119
+		if (!is_array($data)) {
120 120
 			throw new ProviderException('unable to parse token response');
121 121
 		}
122 122
 
123
-		foreach(['error_description', 'error'] as $field){
123
+		foreach (['error_description', 'error'] as $field) {
124 124
 
125
-			if(isset($data[$field])){
125
+			if (isset($data[$field])) {
126 126
 				throw new ProviderException('error retrieving access token: "'.$data[$field].'"');
127 127
 			}
128 128
 
129 129
 		}
130 130
 
131
-		if(!isset($data['access_token'])){
131
+		if (!isset($data['access_token'])) {
132 132
 			throw new ProviderException('token missing');
133 133
 		}
134 134
 
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 */
155 155
 	public function getAccessToken(string $code, string $state = null):AccessToken{
156 156
 
157
-		if($this instanceof CSRFToken){
157
+		if ($this instanceof CSRFToken) {
158 158
 			$this->checkState($state);
159 159
 		}
160 160
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 		$token = $this->storage->getAccessToken($this->serviceName);
209 209
 
210 210
 		// attempt to refresh an expired token
211
-		if($this->options->tokenAutoRefresh && $this instanceof TokenRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){
211
+		if ($this->options->tokenAutoRefresh && $this instanceof TokenRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) {
212 212
 			$token = $this->refreshAccessToken($token);
213 213
 		}
214 214
 
@@ -217,15 +217,15 @@  discard block
 block discarded – undo
217 217
 		$params  = array_merge($query, $params ?? []);
218 218
 		$headers = $headers ?? [];
219 219
 
220
-		if(array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)){
220
+		if (array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)) {
221 221
 			$headers = array_merge($headers, [
222 222
 				'Authorization' => $this::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken,
223 223
 			]);
224 224
 		}
225
-		elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){
225
+		elseif (array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)) {
226 226
 			$params[$this::AUTH_METHODS_QUERY[$this->authMethod]] = $token->accessToken;
227 227
 		}
228
-		else{
228
+		else {
229 229
 			throw new ProviderException('invalid auth type');
230 230
 		}
231 231
 
Please login to merge, or discard this patch.
src/Storage/DBStorage.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 use chillerlan\OAuth\Core\AccessToken;
17 17
 use chillerlan\Traits\ImmutableSettingsInterface;
18 18
 
19
-class DBStorage extends OAuthStorageAbstract{
19
+class DBStorage extends OAuthStorageAbstract {
20 20
 
21 21
 	/**
22 22
 	 * @var \chillerlan\Database\Database
@@ -31,10 +31,10 @@  discard block
 block discarded – undo
31 31
 	 *
32 32
 	 * @throws \chillerlan\OAuth\Storage\OAuthStorageException
33 33
 	 */
34
-	public function __construct(ImmutableSettingsInterface $options, Database $db){
34
+	public function __construct(ImmutableSettingsInterface $options, Database $db) {
35 35
 		parent::__construct($options);
36 36
 
37
-		if(!$this->options->dbTokenTable || !$this->options->dbProviderTable){
37
+		if (!$this->options->dbTokenTable || !$this->options->dbProviderTable) {
38 38
 			throw new OAuthStorageException('invalid table config');
39 39
 		}
40 40
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{
63 63
 		$providers = $this->getProviders();
64 64
 
65
-		if(empty($providers) || !isset($providers[$service])){
65
+		if (empty($providers) || !isset($providers[$service])) {
66 66
 			throw new OAuthStorageException('unknown service');
67 67
 		}
68 68
 
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 			$this->options->dbTokenTableExpires    => $token->expires,
74 74
 		];
75 75
 
76
-		if($this->hasAccessToken($service) === true){
76
+		if ($this->hasAccessToken($service) === true) {
77 77
 			$this->db->update
78 78
 				->table($this->options->dbTokenTable)
79 79
 				->set($values)
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 			->where($this->options->dbTokenTableLabel, $this->getLabel($service))
108 108
 			->query();
109 109
 
110
-		if(is_bool($r) || $r->length < 1){
110
+		if (is_bool($r) || $r->length < 1) {
111 111
 			throw new OAuthStorageException('token not found');
112 112
 		}
113 113
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 			->where($this->options->dbTokenTableLabel, $this->getLabel($service))
188 188
 			->query();
189 189
 
190
-		if(is_bool($r) || $r->length < 1){
190
+		if (is_bool($r) || $r->length < 1) {
191 191
 			throw new OAuthStorageException('state not found');
192 192
 		}
193 193
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 			->where($this->options->dbTokenTableLabel, $this->getLabel($service))
208 208
 			->query();
209 209
 
210
-		if(is_bool($r) || $r->length < 1 || empty(trim($r[0]->state))){
210
+		if (is_bool($r) || $r->length < 1 || empty(trim($r[0]->state))) {
211 211
 			return false;
212 212
 		}
213 213
 
Please login to merge, or discard this patch.
src/Storage/OAuthStorageAbstract.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 * @param \chillerlan\Traits\ImmutableSettingsInterface|null $options
35 35
 	 * @param \Psr\Log\LoggerInterface|null              $logger
36 36
 	 */
37
-	public function __construct(ImmutableSettingsInterface $options = null, LoggerInterface $logger = null){
37
+	public function __construct(ImmutableSettingsInterface $options = null, LoggerInterface $logger = null) {
38 38
 		$this->options = $options ?? new OAuthOptions;
39 39
 		$this->logger  = $logger ?? new NullLogger;
40 40
 	}
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 
50 50
 		unset($token);
51 51
 
52
-		if($this->options->useEncryption === true){
52
+		if ($this->options->useEncryption === true) {
53 53
 			return $this->encrypt($data);
54 54
 		}
55 55
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 */
64 64
 	public function fromStorage(string $data):AccessToken{
65 65
 
66
-		if($this->options->useEncryption === true){
66
+		if ($this->options->useEncryption === true) {
67 67
 			$data = $this->decrypt($data);
68 68
 		}
69 69
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 */
79 79
 	protected function encrypt(string &$data):string {
80 80
 
81
-		if(function_exists('sodium_crypto_secretbox')){
81
+		if (function_exists('sodium_crypto_secretbox')) {
82 82
 			$box = sodium_crypto_secretbox($data, $this::TOKEN_NONCE, sodium_hex2bin($this->options->storageCryptoKey));
83 83
 
84 84
 			sodium_memzero($data);
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	 */
98 98
 	protected function decrypt(string $box):string {
99 99
 
100
-		if(function_exists('sodium_crypto_secretbox_open')){
100
+		if (function_exists('sodium_crypto_secretbox_open')) {
101 101
 			return sodium_crypto_secretbox_open(sodium_hex2bin($box), $this::TOKEN_NONCE, sodium_hex2bin($this->options->storageCryptoKey));
102 102
 		}
103 103
 
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\Traits\ImmutableSettingsInterface;
17 17
 
18
-class SessionStorage extends OAuthStorageAbstract{
18
+class SessionStorage extends OAuthStorageAbstract {
19 19
 
20 20
 	/**
21 21
 	 * @var bool
@@ -37,21 +37,21 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @param \chillerlan\Traits\ImmutableSettingsInterface|null $options
39 39
 	 */
40
-	public function __construct(ImmutableSettingsInterface $options = null){
40
+	public function __construct(ImmutableSettingsInterface $options = null) {
41 41
 		parent::__construct($options);
42 42
 
43 43
 		$this->sessionVar = $this->options->sessionTokenVar;
44 44
 		$this->stateVar = $this->options->sessionStateVar;
45 45
 
46
-		if($this->options->sessionStart && !$this->sessionIsActive()){
46
+		if ($this->options->sessionStart && !$this->sessionIsActive()) {
47 47
 			session_start();
48 48
 		}
49 49
 
50
-		if(!isset($_SESSION[$this->sessionVar])){
50
+		if (!isset($_SESSION[$this->sessionVar])) {
51 51
 			$_SESSION[$this->sessionVar] = [];
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
 	}
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
 	public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{
78 78
 		$token = $token->__toJSON();
79 79
 
80
-		if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){
80
+		if (isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])) {
81 81
 			$_SESSION[$this->sessionVar][$service] = $token;
82 82
 		}
83
-		else{
83
+		else {
84 84
 			$_SESSION[$this->sessionVar] = [$service => $token];
85 85
 		}
86 86
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 */
96 96
 	public function getAccessToken(string $service):AccessToken{
97 97
 
98
-		if($this->hasAccessToken($service)){
98
+		if ($this->hasAccessToken($service)) {
99 99
 			return (new AccessToken)->__fromJSON($_SESSION[$this->sessionVar][$service]);
100 100
 		}
101 101
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	public function clearAccessToken(string $service):OAuthStorageInterface{
120 120
 
121
-		if(array_key_exists($service, $_SESSION[$this->sessionVar])){
121
+		if (array_key_exists($service, $_SESSION[$this->sessionVar])) {
122 122
 			unset($_SESSION[$this->sessionVar][$service]);
123 123
 		}
124 124
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 */
131 131
 	public function clearAllAccessTokens():OAuthStorageInterface{
132 132
 
133
-		foreach(array_keys($_SESSION[$this->sessionVar]) as $service){
133
+		foreach (array_keys($_SESSION[$this->sessionVar]) as $service) {
134 134
 			unset($_SESSION[$this->sessionVar][$service]); // trigger the memzero destructor
135 135
 		}
136 136
 
@@ -147,10 +147,10 @@  discard block
 block discarded – undo
147 147
 	 */
148 148
 	public function storeCSRFState(string $service, string $state):OAuthStorageInterface{
149 149
 
150
-		if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){
150
+		if (isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])) {
151 151
 			$_SESSION[$this->stateVar][$service] = $state;
152 152
 		}
153
-		else{
153
+		else {
154 154
 			$_SESSION[$this->stateVar] = [$service => $state];
155 155
 		}
156 156
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 */
166 166
 	public function getCSRFState(string $service):string{
167 167
 
168
-		if($this->hasCSRFState($service)){
168
+		if ($this->hasCSRFState($service)) {
169 169
 			return $_SESSION[$this->stateVar][$service];
170 170
 		}
171 171
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 */
189 189
 	public function clearCSRFState(string $service):OAuthStorageInterface{
190 190
 
191
-		if(array_key_exists($service, $_SESSION[$this->stateVar])){
191
+		if (array_key_exists($service, $_SESSION[$this->stateVar])) {
192 192
 			unset($_SESSION[$this->stateVar][$service]);
193 193
 		}
194 194
 
Please login to merge, or discard this patch.