Passed
Push — master ( 7452e9...3b4930 )
by smiley
01:54
created
src/Storage/OAuthStorageAbstract.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 * @param \chillerlan\Traits\ContainerInterface|null $options
37 37
 	 * @param \Psr\Log\LoggerInterface|null              $logger
38 38
 	 */
39
-	public function __construct(ContainerInterface $options = null, LoggerInterface $logger = null){
39
+	public function __construct(ContainerInterface $options = null, LoggerInterface $logger = null) {
40 40
 		$this->options = $options ?? new OAuthOptions;
41 41
 		$this->logger  = $logger ?? new NullLogger;
42 42
 	}
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
 		unset($token);
53 53
 
54
-		if($this->options->useEncryption === true){
54
+		if ($this->options->useEncryption === true) {
55 55
 			return $this->encrypt($data);
56 56
 		}
57 57
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 */
66 66
 	public function fromStorage(string $data):AccessToken{
67 67
 
68
-		if($this->options->useEncryption === true){
68
+		if ($this->options->useEncryption === true) {
69 69
 			$data = $this->decrypt($data);
70 70
 		}
71 71
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
 	protected function encrypt(string &$data):string {
82 82
 
83
-		if(function_exists('sodium_crypto_secretbox')){
83
+		if (function_exists('sodium_crypto_secretbox')) {
84 84
 			$box = sodium_crypto_secretbox($data, $this::TOKEN_NONCE, sodium_hex2bin($this->options->storageCryptoKey));
85 85
 
86 86
 			sodium_memzero($data);
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	protected function decrypt(string $box):string {
101 101
 
102
-		if(function_exists('sodium_crypto_secretbox_open')){
102
+		if (function_exists('sodium_crypto_secretbox_open')) {
103 103
 			return sodium_crypto_secretbox_open(sodium_hex2bin($box), $this::TOKEN_NONCE, sodium_hex2bin($this->options->storageCryptoKey));
104 104
 		}
105 105
 
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/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\ContainerInterface;
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(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 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/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\Traits\ContainerInterface;
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\ContainerInterface|null $options
39 39
 	 */
40
-	public function __construct(ContainerInterface $options = null){
40
+	public function __construct(ContainerInterface $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.
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   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 ];
62 62
 
63 63
 /** @var \chillerlan\Traits\ContainerInterface $options */
64
-$options = new class($options_arr) extends OAuthOptions{
64
+$options = new class($options_arr) extends OAuthOptions {
65 65
 	use DatabaseOptionsTrait, LogOptionsTrait;
66 66
 
67 67
 	protected $sleep;
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
 $logger->addInstance(new ConsoleLog($options), 'console');
72 72
 
73 73
 /** @var \chillerlan\HTTP\HTTPClientInterface $http */
74
-$http = new class($options) extends HTTPClientAbstract{
74
+$http = new class($options) extends HTTPClientAbstract {
75 75
 
76 76
 	protected $client;
77 77
 
78
-	public function __construct(ContainerInterface $options){
78
+	public function __construct(ContainerInterface $options) {
79 79
 		parent::__construct($options);
80 80
 		$this->client = new CurlClient($this->options);
81 81
 	}
Please login to merge, or discard this patch.