Completed
Push — master ( a8c357...0fae25 )
by smiley
01:52
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/API/OAuthAPIClientException.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 OAuthAPIClientException extends OAuthException{}
17
+class OAuthAPIClientException extends OAuthException {}
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/MemoryTokenStorage.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\Token;
16 16
 
17
-class MemoryTokenStorage extends TokenStorageAbstract{
17
+class MemoryTokenStorage extends TokenStorageAbstract {
18 18
 
19 19
 	/**
20 20
 	 * @var array
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 */
47 47
 	public function retrieveAccessToken(string $service):Token{
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):TokenStorageInterface{
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():TokenStorageInterface{
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 retrieveAuthorizationState(string $service):string{
112 112
 
113
-		if($this->hasAuthorizationState($service)){
113
+		if ($this->hasAuthorizationState($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 clearAuthorizationState(string $service):TokenStorageInterface{
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/SessionTokenStorage.php 2 patches
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 retrieveAccessToken(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 storeAuthorizationState(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 retrieveAuthorizationState(string $service):string{
171 171
 
172
-		if($this->hasAuthorizationState($service)){
172
+		if ($this->hasAuthorizationState($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 clearAuthorizationState(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.
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.
src/Storage/DBTokenStorage.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\Token;
17 17
 use chillerlan\Traits\ContainerInterface;
18 18
 
19
-class DBTokenStorage extends TokenStorageAbstract{
19
+class DBTokenStorage extends TokenStorageAbstract {
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\TokenStorageException
33 33
 	 */
34
-	public function __construct(ContainerInterface $options, Database $db){
34
+	public function __construct(ContainerInterface $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 TokenStorageException('invalid table config');
39 39
 		}
40 40
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	public function storeAccessToken(string $service, Token $token):TokenStorageInterface{
63 63
 
64
-		if(!isset($this->getProviders()[$service])){
64
+		if (!isset($this->getProviders()[$service])) {
65 65
 			throw new TokenStorageException('unknown service');
66 66
 		}
67 67
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 			$this->options->dbTokenTableExpires    => $token->expires,
73 73
 		];
74 74
 
75
-		if($this->hasAccessToken($service) === true){
75
+		if ($this->hasAccessToken($service) === true) {
76 76
 			$this->db->update
77 77
 				->table($this->options->dbTokenTable)
78 78
 				->set($values)
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 			->where($this->options->dbTokenTableLabel, $this->getLabel($service))
107 107
 			->query();
108 108
 
109
-		if(is_bool($r) || $r->length < 1){
109
+		if (is_bool($r) || $r->length < 1) {
110 110
 			throw new TokenStorageException('token not found');
111 111
 		}
112 112
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 			->where($this->options->dbTokenTableLabel, $this->getLabel($service))
187 187
 			->query();
188 188
 
189
-		if(is_bool($r) || $r->length < 1){
189
+		if (is_bool($r) || $r->length < 1) {
190 190
 			throw new TokenStorageException('state not found');
191 191
 		}
192 192
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 			->where($this->options->dbTokenTableLabel, $this->getLabel($service))
207 207
 			->query();
208 208
 
209
-		if(is_bool($r) || $r->length < 1 || empty(trim($r[0]->state))){
209
+		if (is_bool($r) || $r->length < 1 || empty(trim($r[0]->state))) {
210 210
 			return false;
211 211
 		}
212 212
 
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.