@@ -38,7 +38,7 @@ |
||
| 38 | 38 | * |
| 39 | 39 | * @return Tiqr_UserSecretStorage_Encryption_Interface |
| 40 | 40 | */ |
| 41 | - public static function getEncryption(LoggerInterface $logger, string $type="dummy", array $options=array()): Tiqr_UserSecretStorage_Encryption_Interface |
|
| 41 | + public static function getEncryption(LoggerInterface $logger, string $type = "dummy", array $options = array()): Tiqr_UserSecretStorage_Encryption_Interface |
|
| 42 | 42 | { |
| 43 | 43 | $instance = null; |
| 44 | 44 | $logger->info(sprintf('Using "%s" as UserSecretStorage encryption type', $type)); |
@@ -160,7 +160,7 @@ |
||
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
| 163 | - * Decrypts the given data. |
|
| 163 | + * Decrypts the given data. |
|
| 164 | 164 | * |
| 165 | 165 | * @param string $data Data to decrypt. |
| 166 | 166 | * @return string decrypted data |
@@ -48,22 +48,22 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | |
| 50 | 50 | private $_supportedCiphers = [ |
| 51 | - 'aes-128-cbc' => [ 'tag' => false, 'key' => 16 ], |
|
| 52 | - 'aes-128-gcm' => [ 'tag' => true, 'key' => 16 ], |
|
| 53 | - 'aes-192-cbc' => [ 'tag' => false, 'key' => 24 ], |
|
| 54 | - 'aes-192-gcm' => [ 'tag' => true, 'key' => 24 ], |
|
| 55 | - 'aes-256-cbc' => [ 'tag' => false, 'key' => 32 ], |
|
| 56 | - 'aes-256-gcm' => [ 'tag' => true, 'key' => 32 ], |
|
| 57 | - 'chacha20' => [ 'tag' => false, 'key' => 32 ], |
|
| 58 | - 'camellia-128-cbc' => [ 'tag' => false, 'key' => 16 ], |
|
| 59 | - 'camellia-192-cbc' => [ 'tag' => false, 'key' => 24 ], |
|
| 60 | - 'camellia-256-cbc' => [ 'tag' => false, 'key' => 32 ], |
|
| 61 | - 'aria-128-cbc' => [ 'tag' => false, 'key' => 16 ], |
|
| 62 | - 'aria-128-gcm' => [ 'tag' => true, 'key' => 16 ], |
|
| 63 | - 'aria-192-cbc' => [ 'tag' => false, 'key' => 24 ], |
|
| 64 | - 'aria-192-gcm' => [ 'tag' => true, 'key' => 24 ], |
|
| 65 | - 'aria-256-cbc' => [ 'tag' => false, 'key' => 32 ], |
|
| 66 | - 'aria-256-gcm' => [ 'tag' => true, 'key' => 32 ], |
|
| 51 | + 'aes-128-cbc' => ['tag' => false, 'key' => 16], |
|
| 52 | + 'aes-128-gcm' => ['tag' => true, 'key' => 16], |
|
| 53 | + 'aes-192-cbc' => ['tag' => false, 'key' => 24], |
|
| 54 | + 'aes-192-gcm' => ['tag' => true, 'key' => 24], |
|
| 55 | + 'aes-256-cbc' => ['tag' => false, 'key' => 32], |
|
| 56 | + 'aes-256-gcm' => ['tag' => true, 'key' => 32], |
|
| 57 | + 'chacha20' => ['tag' => false, 'key' => 32], |
|
| 58 | + 'camellia-128-cbc' => ['tag' => false, 'key' => 16], |
|
| 59 | + 'camellia-192-cbc' => ['tag' => false, 'key' => 24], |
|
| 60 | + 'camellia-256-cbc' => ['tag' => false, 'key' => 32], |
|
| 61 | + 'aria-128-cbc' => ['tag' => false, 'key' => 16], |
|
| 62 | + 'aria-128-gcm' => ['tag' => true, 'key' => 16], |
|
| 63 | + 'aria-192-cbc' => ['tag' => false, 'key' => 24], |
|
| 64 | + 'aria-192-gcm' => ['tag' => true, 'key' => 24], |
|
| 65 | + 'aria-256-cbc' => ['tag' => false, 'key' => 32], |
|
| 66 | + 'aria-256-gcm' => ['tag' => true, 'key' => 32], |
|
| 67 | 67 | ]; |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -136,12 +136,12 @@ discard block |
||
| 136 | 136 | // A longer key is not a problem, but could indicate a configuration error |
| 137 | 137 | $key_length = $this->_supportedCiphers[$this->_cipher]['key']; |
| 138 | 138 | if (strlen($key) != $key_length) { |
| 139 | - throw new RuntimeException("Invalid length of key with key_id '{$this->_key_id}' used with cipher '{$this->_cipher}', expected {$key_length} bytes, got " . strlen($key) . " bytes"); |
|
| 139 | + throw new RuntimeException("Invalid length of key with key_id '{$this->_key_id}' used with cipher '{$this->_cipher}', expected {$key_length} bytes, got ".strlen($key)." bytes"); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // openssl_encrypt returns the ciphertext as a base64 encoded string, so we don't need to encode it again |
| 143 | 143 | // The tag is returned as a binary string, but only if the cipher requires a tag |
| 144 | - $tag=''; |
|
| 144 | + $tag = ''; |
|
| 145 | 145 | if ($this->_supportedCiphers[$this->_cipher]['tag']) { |
| 146 | 146 | $encrypted = openssl_encrypt($data, $this->_cipher, $key, 0, $iv, $tag, '', 16); |
| 147 | 147 | } else { |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | $tag = $this->_supportedCiphers[$this->_cipher]['tag'] ? $tag : ''; |
| 154 | 154 | // Return the encoded ciphertext, including the IV, tag and cipher |
| 155 | 155 | // <cipher>:<key_id>:iv<>:<tag>:<ciphertext> |
| 156 | - $encoded = $this->_cipher . ":" . $this->_key_id . ":" . base64_encode($iv) . ":" . base64_encode($tag) . ":" . $encrypted; |
|
| 156 | + $encoded = $this->_cipher.":".$this->_key_id.":".base64_encode($iv).":".base64_encode($tag).":".$encrypted; |
|
| 157 | 157 | |
| 158 | 158 | return $encoded; |
| 159 | 159 | } |
@@ -192,19 +192,19 @@ discard block |
||
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | // IV |
| 195 | - $iv = base64_decode($split_data[2],true); |
|
| 195 | + $iv = base64_decode($split_data[2], true); |
|
| 196 | 196 | if ($iv === false) { |
| 197 | 197 | throw new RuntimeException("Error decoding IV"); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Tag |
| 201 | - $tag = base64_decode($split_data[3],true); |
|
| 201 | + $tag = base64_decode($split_data[3], true); |
|
| 202 | 202 | if ($tag === false) { |
| 203 | 203 | throw new RuntimeException("Error decoding tag"); |
| 204 | 204 | } |
| 205 | 205 | $ciphertext = $split_data[4]; |
| 206 | 206 | |
| 207 | - $plaintext=openssl_decrypt($ciphertext, $cipher, $key, 0, $iv, $tag); |
|
| 207 | + $plaintext = openssl_decrypt($ciphertext, $cipher, $key, 0, $iv, $tag); |
|
| 208 | 208 | if ($plaintext === false) { |
| 209 | 209 | throw new RuntimeException("Error decrypting data"); |
| 210 | 210 | } |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | - * Decrypts the given data. |
|
| 60 | + * Decrypts the given data. |
|
| 61 | 61 | * |
| 62 | 62 | * @param String $data Data to decrypt. |
| 63 | 63 | * |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | { |
| 41 | 41 | $url = $this->_options["url"]."?appId=".$this->_options["appid"]; |
| 42 | 42 | |
| 43 | - $url.= "¬ificationToken=".$notificationToken; |
|
| 43 | + $url .= "¬ificationToken=".$notificationToken; |
|
| 44 | 44 | |
| 45 | 45 | $ch = curl_init(); |
| 46 | 46 | |
@@ -53,12 +53,12 @@ discard block |
||
| 53 | 53 | $output = curl_exec($ch); |
| 54 | 54 | curl_close($ch); |
| 55 | 55 | |
| 56 | - if (stripos($output, "not found")!==false) { |
|
| 56 | + if (stripos($output, "not found") !== false) { |
|
| 57 | 57 | $this->logger->error('Token Exchange failed and responded with: not found', ['full output' => $output]); |
| 58 | 58 | return false; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - if (stripos($output, "error")!==false) { |
|
| 61 | + if (stripos($output, "error") !== false) { |
|
| 62 | 62 | $this->logger->error('Token Exchange failed and responded with: error', ['full output' => $output]); |
| 63 | 63 | return false; |
| 64 | 64 | } |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | private function cleanExpired(): void { |
| 119 | 119 | try { |
| 120 | - $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `expire` < ? AND NOT `expire` = 0"); |
|
| 120 | + $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `expire` < ? AND NOT `expire` = 0"); |
|
| 121 | 121 | $sth->execute(array(time())); |
| 122 | - $deletedRows=$sth->rowCount(); |
|
| 122 | + $deletedRows = $sth->rowCount(); |
|
| 123 | 123 | $this->logger->notice( |
| 124 | 124 | sprintf("Deleted %d expired keys", $deletedRows) |
| 125 | 125 | ); |
@@ -135,12 +135,12 @@ discard block |
||
| 135 | 135 | /** |
| 136 | 136 | * @see Tiqr_StateStorage_StateStorageInterface::setValue() |
| 137 | 137 | */ |
| 138 | - public function setValue(string $key, $value, int $expire=0): void |
|
| 138 | + public function setValue(string $key, $value, int $expire = 0): void |
|
| 139 | 139 | { |
| 140 | 140 | if (empty($key)) { |
| 141 | 141 | throw new InvalidArgumentException('Empty key not allowed'); |
| 142 | 142 | } |
| 143 | - if (((float) rand() /(float) getrandmax()) < $this->cleanupProbability) { |
|
| 143 | + if (((float) rand() / (float) getrandmax()) < $this->cleanupProbability) { |
|
| 144 | 144 | $this->cleanExpired(); |
| 145 | 145 | } |
| 146 | 146 | // REPLACE INTO is mysql dialect. Supported by sqlite as well. |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | // $expire == 0 means never expire |
| 155 | 155 | if ($expire != 0) { |
| 156 | - $expire+=time(); // Store unix timestamp after which the key expires |
|
| 156 | + $expire += time(); // Store unix timestamp after which the key expires |
|
| 157 | 157 | } |
| 158 | 158 | try { |
| 159 | 159 | $sth->execute(array(serialize($value), $expire, $key)); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | throw new InvalidArgumentException('Empty key not allowed'); |
| 177 | 177 | } |
| 178 | 178 | try { |
| 179 | - $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?"); |
|
| 179 | + $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `key` = ?"); |
|
| 180 | 180 | $sth->execute(array($key)); |
| 181 | 181 | } |
| 182 | 182 | catch (Exception $e) { |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | try { |
| 209 | - $sth = $this->handle->prepare('SELECT `value` FROM ' . $this->tablename . ' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)'); |
|
| 209 | + $sth = $this->handle->prepare('SELECT `value` FROM '.$this->tablename.' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)'); |
|
| 210 | 210 | $sth->execute(array($key, time())); |
| 211 | 211 | } |
| 212 | 212 | catch (Exception $e) { |
@@ -220,9 +220,9 @@ discard block |
||
| 220 | 220 | if (false === $result) { |
| 221 | 221 | // Occurs normally |
| 222 | 222 | $this->logger->info(sprintf('getValue: Key "%s" not found in PDO StateStorage', $key)); |
| 223 | - return NULL; // Key not found |
|
| 223 | + return NULL; // Key not found |
|
| 224 | 224 | } |
| 225 | - $result=unserialize($result, array('allowed_classes' => false)); |
|
| 225 | + $result = unserialize($result, array('allowed_classes' => false)); |
|
| 226 | 226 | if (false === $result) { |
| 227 | 227 | throw new RuntimeException(sprintf('getValue: unserialize error for key "%s" in PDO StateStorage', $key)); |
| 228 | 228 | } |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | { |
| 238 | 238 | try { |
| 239 | 239 | // Retrieve a random row from the table, this checks that the table exists and is readable |
| 240 | - $sth = $this->handle->prepare('SELECT `value`, `key`, `expire` FROM ' . $this->tablename . ' LIMIT 1'); |
|
| 240 | + $sth = $this->handle->prepare('SELECT `value`, `key`, `expire` FROM '.$this->tablename.' LIMIT 1'); |
|
| 241 | 241 | $sth->execute(); |
| 242 | 242 | } |
| 243 | 243 | catch (Exception $e) { |
@@ -123,8 +123,7 @@ discard block |
||
| 123 | 123 | $this->logger->notice( |
| 124 | 124 | sprintf("Deleted %d expired keys", $deletedRows) |
| 125 | 125 | ); |
| 126 | - } |
|
| 127 | - catch (Exception $e) { |
|
| 126 | + } catch (Exception $e) { |
|
| 128 | 127 | $this->logger->error( |
| 129 | 128 | sprintf("Deleting expired keys failed: %s", $e->getMessage()), |
| 130 | 129 | array('exception', $e) |
@@ -157,8 +156,7 @@ discard block |
||
| 157 | 156 | } |
| 158 | 157 | try { |
| 159 | 158 | $sth->execute(array(serialize($value), $expire, $key)); |
| 160 | - } |
|
| 161 | - catch (Exception $e) { |
|
| 159 | + } catch (Exception $e) { |
|
| 162 | 160 | $this->logger->error( |
| 163 | 161 | sprintf('Unable to store key "%s" in PDO StateStorage', $key), |
| 164 | 162 | array('exception' => $e) |
@@ -178,8 +176,7 @@ discard block |
||
| 178 | 176 | try { |
| 179 | 177 | $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?"); |
| 180 | 178 | $sth->execute(array($key)); |
| 181 | - } |
|
| 182 | - catch (Exception $e) { |
|
| 179 | + } catch (Exception $e) { |
|
| 183 | 180 | $this->logger->error( |
| 184 | 181 | sprintf('Error deleting key "%s" from PDO StateStorage', $key), |
| 185 | 182 | array('exception' => $e) |
@@ -208,8 +205,7 @@ discard block |
||
| 208 | 205 | try { |
| 209 | 206 | $sth = $this->handle->prepare('SELECT `value` FROM ' . $this->tablename . ' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)'); |
| 210 | 207 | $sth->execute(array($key, time())); |
| 211 | - } |
|
| 212 | - catch (Exception $e) { |
|
| 208 | + } catch (Exception $e) { |
|
| 213 | 209 | $this->logger->error( |
| 214 | 210 | sprintf('Error getting value for key "%s" from PDO StateStorage', $key), |
| 215 | 211 | array('exception' => $e) |
@@ -239,8 +235,7 @@ discard block |
||
| 239 | 235 | // Retrieve a random row from the table, this checks that the table exists and is readable |
| 240 | 236 | $sth = $this->handle->prepare('SELECT `value`, `key`, `expire` FROM ' . $this->tablename . ' LIMIT 1'); |
| 241 | 237 | $sth->execute(); |
| 242 | - } |
|
| 243 | - catch (Exception $e) { |
|
| 238 | + } catch (Exception $e) { |
|
| 244 | 239 | $statusMessage = sprintf('Error performing health check on PDO StateStorage: %s', $e->getMessage()); |
| 245 | 240 | return false; |
| 246 | 241 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * The default configuration |
| 52 | 52 | */ |
| 53 | 53 | const DEFAULT_HOST = '127.0.0.1'; |
| 54 | - const DEFAULT_PORT = 11211; |
|
| 54 | + const DEFAULT_PORT = 11211; |
|
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * Get the prefix to use for all keys in memcache. |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | /** |
| 107 | 107 | * @see Tiqr_StateStorage_StateStorageInterface::setValue() |
| 108 | 108 | */ |
| 109 | - public function setValue(string $key, $value, int $expire=0): void |
|
| 109 | + public function setValue(string $key, $value, int $expire = 0): void |
|
| 110 | 110 | { |
| 111 | 111 | if (empty($key)) { |
| 112 | 112 | throw new InvalidArgumentException('Empty key not allowed'); |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | if ($result === false) { |
| 161 | 161 | // Memcache interface does not provide error information, either the key does not exist or |
| 162 | 162 | // there was an error communicating with the memcache |
| 163 | - $this->logger->info( sprintf('Unable to get key "%s" from memcache StateStorage', $key) ); |
|
| 163 | + $this->logger->info(sprintf('Unable to get key "%s" from memcache StateStorage', $key)); |
|
| 164 | 164 | return null; |
| 165 | 165 | } |
| 166 | 166 | return $result; |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | $key = bin2hex(random_bytes(16)); |
| 177 | 177 | $this->setValue($key, 'healthcheck', 10); |
| 178 | 178 | } catch (Exception $e) { |
| 179 | - $statusMessage = 'Unable to store key in memcache: ' . $e->getMessage(); |
|
| 179 | + $statusMessage = 'Unable to store key in memcache: '.$e->getMessage(); |
|
| 180 | 180 | return false; |
| 181 | 181 | } |
| 182 | 182 | |
@@ -71,6 +71,6 @@ |
||
| 71 | 71 | */ |
| 72 | 72 | public function healthCheck(string &$statusMessage = ''): bool |
| 73 | 73 | { |
| 74 | - return true; // Health check is always successful when not implemented |
|
| 74 | + return true; // Health check is always successful when not implemented |
|
| 75 | 75 | } |
| 76 | 76 | } |
@@ -98,21 +98,21 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | private function _getStringValue(string $columnName, string $userId): string |
| 100 | 100 | { |
| 101 | - if ( !in_array($columnName, $this->_allowedStringColumns) ) { |
|
| 101 | + if (!in_array($columnName, $this->_allowedStringColumns)) { |
|
| 102 | 102 | throw new InvalidArgumentException('Unsupported column name'); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | try { |
| 106 | - $sth = $this->handle->prepare('SELECT ' . $columnName . ' FROM ' . $this->tablename . ' WHERE userid = ?'); |
|
| 106 | + $sth = $this->handle->prepare('SELECT '.$columnName.' FROM '.$this->tablename.' WHERE userid = ?'); |
|
| 107 | 107 | $sth->execute(array($userId)); |
| 108 | - $res=$sth->fetchColumn(); |
|
| 108 | + $res = $sth->fetchColumn(); |
|
| 109 | 109 | if ($res === false) { |
| 110 | 110 | // No result |
| 111 | 111 | $this->logger->error(sprintf('No result getting "%s" for user "%s"', $columnName, $userId)); |
| 112 | 112 | throw new RuntimeException('User not found'); |
| 113 | 113 | } |
| 114 | 114 | if ($res === NULL) { |
| 115 | - return ''; // Value unset |
|
| 115 | + return ''; // Value unset |
|
| 116 | 116 | } |
| 117 | 117 | if (!is_string($res)) { |
| 118 | 118 | $this->logger->error(sprintf('Expected string type while getting "%s" for user "%s"', $columnName, $userId)); |
@@ -136,28 +136,28 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | private function _getIntValue(string $columnName, string $userId): int |
| 138 | 138 | { |
| 139 | - if ( !in_array($columnName, $this->_allowedIntColumns) ) { |
|
| 139 | + if (!in_array($columnName, $this->_allowedIntColumns)) { |
|
| 140 | 140 | throw new InvalidArgumentException('Unsupported column name'); |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | try { |
| 144 | - $sth = $this->handle->prepare('SELECT ' . $columnName . ' FROM ' . $this->tablename . ' WHERE userid = ?'); |
|
| 144 | + $sth = $this->handle->prepare('SELECT '.$columnName.' FROM '.$this->tablename.' WHERE userid = ?'); |
|
| 145 | 145 | $sth->execute(array($userId)); |
| 146 | - $res=$sth->fetchColumn(); |
|
| 146 | + $res = $sth->fetchColumn(); |
|
| 147 | 147 | if ($res === false) { |
| 148 | 148 | // No result |
| 149 | 149 | $this->logger->error(sprintf('No result getting "%s" for user "%s"', $columnName, $userId)); |
| 150 | 150 | throw new RuntimeException('User not found'); |
| 151 | 151 | } |
| 152 | 152 | if ($res === NULL) { |
| 153 | - return 0; // Value unset |
|
| 153 | + return 0; // Value unset |
|
| 154 | 154 | } |
| 155 | 155 | // Return type for integers depends on the PDO driver, can be string |
| 156 | 156 | if (!is_numeric($res)) { |
| 157 | 157 | $this->logger->error(sprintf('Expected int type while getting "%s" for user "%s"', $columnName, $userId)); |
| 158 | 158 | throw new RuntimeException('Unexpected return type'); |
| 159 | 159 | } |
| 160 | - return (int)$res; |
|
| 160 | + return (int) $res; |
|
| 161 | 161 | } |
| 162 | 162 | catch (Exception $e) { |
| 163 | 163 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
@@ -174,11 +174,11 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | private function _setStringValue(string $columnName, string $userId, string $value): void |
| 176 | 176 | { |
| 177 | - if ( !in_array($columnName, $this->_allowedStringColumns) ) { |
|
| 177 | + if (!in_array($columnName, $this->_allowedStringColumns)) { |
|
| 178 | 178 | throw new InvalidArgumentException('Unsupported column name'); |
| 179 | 179 | } |
| 180 | 180 | try { |
| 181 | - $sth = $this->handle->prepare('UPDATE ' . $this->tablename . ' SET ' . $columnName . ' = ? WHERE userid = ?'); |
|
| 181 | + $sth = $this->handle->prepare('UPDATE '.$this->tablename.' SET '.$columnName.' = ? WHERE userid = ?'); |
|
| 182 | 182 | $sth->execute(array($value, $userId)); |
| 183 | 183 | if ($sth->rowCount() == 0) { |
| 184 | 184 | // Required for mysql which only returns the number of rows that were actually updated |
@@ -202,11 +202,11 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | private function _setIntValue(string $columnName, string $userId, int $value): void |
| 204 | 204 | { |
| 205 | - if ( !in_array($columnName, $this->_allowedIntColumns) ) { |
|
| 205 | + if (!in_array($columnName, $this->_allowedIntColumns)) { |
|
| 206 | 206 | throw new InvalidArgumentException('Unsupported column name'); |
| 207 | 207 | } |
| 208 | 208 | try { |
| 209 | - $sth = $this->handle->prepare('UPDATE ' . $this->tablename . ' SET ' . $columnName . ' = ? WHERE userid = ?'); |
|
| 209 | + $sth = $this->handle->prepare('UPDATE '.$this->tablename.' SET '.$columnName.' = ? WHERE userid = ?'); |
|
| 210 | 210 | $sth->execute(array($value, $userId)); |
| 211 | 211 | if ($sth->rowCount() == 0) { |
| 212 | 212 | // Required for mysql which only returns the number of rows that were actually updated |
@@ -318,17 +318,17 @@ discard block |
||
| 318 | 318 | { |
| 319 | 319 | // Check for blocked |
| 320 | 320 | if ($this->_getIntValue('blocked', $userId) != 0) { |
| 321 | - return true; // Blocked |
|
| 321 | + return true; // Blocked |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | if (0 == $tempBlockDuration) { |
| 325 | - return false; // No check for temporary block |
|
| 325 | + return false; // No check for temporary block |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | // Check for temporary block |
| 329 | 329 | $timestamp = $this->getTemporaryBlockTimestamp($userId); |
| 330 | 330 | // if no temporary block timestamp is set or if the temporary block is expired, return false |
| 331 | - if ( 0 == $timestamp || ($timestamp + $tempBlockDuration * 60) < time()) { |
|
| 331 | + if (0 == $timestamp || ($timestamp + $tempBlockDuration * 60) < time()) { |
|
| 332 | 332 | return false; |
| 333 | 333 | } |
| 334 | 334 | return true; |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | $sth->execute(); |
| 385 | 385 | } |
| 386 | 386 | catch (Exception $e) { |
| 387 | - $statusMessage = "Error reading from UserStorage_PDO: ". $e->getMessage(); |
|
| 387 | + $statusMessage = "Error reading from UserStorage_PDO: ".$e->getMessage(); |
|
| 388 | 388 | return false; |
| 389 | 389 | } |
| 390 | 390 | |
@@ -119,8 +119,7 @@ discard block |
||
| 119 | 119 | throw new RuntimeException('Unexpected return type'); |
| 120 | 120 | } |
| 121 | 121 | return $res; |
| 122 | - } |
|
| 123 | - catch (Exception $e) { |
|
| 122 | + } catch (Exception $e) { |
|
| 124 | 123 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
| 125 | 124 | throw ReadWriteException::fromOriginalException($e); |
| 126 | 125 | } |
@@ -158,8 +157,7 @@ discard block |
||
| 158 | 157 | throw new RuntimeException('Unexpected return type'); |
| 159 | 158 | } |
| 160 | 159 | return (int)$res; |
| 161 | - } |
|
| 162 | - catch (Exception $e) { |
|
| 160 | + } catch (Exception $e) { |
|
| 163 | 161 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
| 164 | 162 | throw ReadWriteException::fromOriginalException($e); |
| 165 | 163 | } |
@@ -186,8 +184,7 @@ discard block |
||
| 186 | 184 | throw new RuntimeException('User not found'); |
| 187 | 185 | } |
| 188 | 186 | } |
| 189 | - } |
|
| 190 | - catch (Exception $e) { |
|
| 187 | + } catch (Exception $e) { |
|
| 191 | 188 | $this->logger->error('PDO error updating user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
| 192 | 189 | throw ReadWriteException::fromOriginalException($e); |
| 193 | 190 | } |
@@ -214,8 +211,7 @@ discard block |
||
| 214 | 211 | throw new RuntimeException('User not found'); |
| 215 | 212 | } |
| 216 | 213 | } |
| 217 | - } |
|
| 218 | - catch (Exception $e) { |
|
| 214 | + } catch (Exception $e) { |
|
| 219 | 215 | $this->logger->error('PDO error updating user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
| 220 | 216 | throw ReadWriteException::fromOriginalException($e); |
| 221 | 217 | } |
@@ -232,8 +228,7 @@ discard block |
||
| 232 | 228 | try { |
| 233 | 229 | $sth = $this->handle->prepare("INSERT INTO ".$this->tablename." (displayname,userid) VALUES (?,?)"); |
| 234 | 230 | $sth->execute(array($displayName, $userId)); |
| 235 | - } |
|
| 236 | - catch (Exception $e) { |
|
| 231 | + } catch (Exception $e) { |
|
| 237 | 232 | $this->logger->error(sprintf('Error creating user "%s"', $userId), array('exception'=>$e)); |
| 238 | 233 | throw new ReadWriteException('The user could not be saved in the user storage (PDO)'); |
| 239 | 234 | } |
@@ -248,8 +243,7 @@ discard block |
||
| 248 | 243 | $sth = $this->handle->prepare("SELECT userid FROM ".$this->tablename." WHERE userid = ?"); |
| 249 | 244 | $sth->execute(array($userId)); |
| 250 | 245 | return (false !== $sth->fetchColumn()); |
| 251 | - } |
|
| 252 | - catch (Exception $e) { |
|
| 246 | + } catch (Exception $e) { |
|
| 253 | 247 | $this->logger->error('PDO error checking user exists', array('exception'=>$e, 'userId'=>$userId)); |
| 254 | 248 | throw ReadWriteException::fromOriginalException($e); |
| 255 | 249 | } |
@@ -382,8 +376,7 @@ discard block |
||
| 382 | 376 | try { |
| 383 | 377 | $sth = $this->handle->prepare('SELECT displayname, notificationtype, notificationaddress, loginattempts, tmpblockattempts, blocked, tmpblocktimestamp FROM '.$this->tablename.' LIMIT 1'); |
| 384 | 378 | $sth->execute(); |
| 385 | - } |
|
| 386 | - catch (Exception $e) { |
|
| 379 | + } catch (Exception $e) { |
|
| 387 | 380 | $statusMessage = "Error reading from UserStorage_PDO: ". $e->getMessage(); |
| 388 | 381 | return false; |
| 389 | 382 | } |
@@ -30,13 +30,11 @@ |
||
| 30 | 30 | notificationtype varchar(15), |
| 31 | 31 | notificationaddress varchar(256) |
| 32 | 32 | ); |
| 33 | - |
|
| 34 | 33 | * |
| 35 | 34 | * In version 3.0 the format of the tmpblocktimestamp was changed from a datetime format to an integer. |
| 36 | 35 | * Because it holds a unix timestamp a 64-bit (8-byte) integer. To upgrade the user table to the new format use: |
| 37 | 36 | |
| 38 | 37 | ALTER TABLE user MODIFY tmpblocktimestamp BIGINT; |
| 39 | - |
|
| 40 | 38 | */ |
| 41 | 39 | |
| 42 | 40 | use Psr\Log\LoggerInterface; |
@@ -74,7 +74,7 @@ |
||
| 74 | 74 | */ |
| 75 | 75 | public function getPath(): string |
| 76 | 76 | { |
| 77 | - if (substr($this->path, -1)!="/") return $this->path."/"; |
|
| 77 | + if (substr($this->path, -1) != "/") return $this->path."/"; |
|
| 78 | 78 | return $this->path; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -74,7 +74,9 @@ |
||
| 74 | 74 | */ |
| 75 | 75 | public function getPath(): string |
| 76 | 76 | { |
| 77 | - if (substr($this->path, -1)!="/") return $this->path."/"; |
|
| 77 | + if (substr($this->path, -1)!="/") { |
|
| 78 | + return $this->path."/"; |
|
| 79 | + } |
|
| 78 | 80 | return $this->path; |
| 79 | 81 | } |
| 80 | 82 | |