@@ -79,7 +79,7 @@ |
||
| 79 | 79 | */ |
| 80 | 80 | private function setUserSecret(string $userId, string $secret): void |
| 81 | 81 | { |
| 82 | - $data=array(); |
|
| 82 | + $data = array(); |
|
| 83 | 83 | if ($this->_userExists($userId)) { |
| 84 | 84 | $data = $this->_loadUser($userId); |
| 85 | 85 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | public function userExists(string $userId): bool |
| 84 | 84 | { |
| 85 | 85 | try { |
| 86 | - $sth = $this->handle->prepare('SELECT userid FROM ' . $this->tableName . ' WHERE userid = ?'); |
|
| 86 | + $sth = $this->handle->prepare('SELECT userid FROM '.$this->tableName.' WHERE userid = ?'); |
|
| 87 | 87 | $sth->execute(array($userId)); |
| 88 | 88 | return (false !== $sth->fetchColumn()); |
| 89 | 89 | } |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | private function getUserSecret(string $userId): string |
| 104 | 104 | { |
| 105 | 105 | try { |
| 106 | - $sth = $this->handle->prepare('SELECT secret FROM ' . $this->tableName . ' WHERE userid = ?'); |
|
| 106 | + $sth = $this->handle->prepare('SELECT secret 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 secret for user "%s"', $userId)); |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | // - The INSERT will fail when displayname has a NOT NULL constraint |
| 142 | 142 | try { |
| 143 | 143 | if ($this->userExists($userId)) { |
| 144 | - $sth = $this->handle->prepare('UPDATE ' . $this->tableName . ' SET secret = ? WHERE userid = ?'); |
|
| 144 | + $sth = $this->handle->prepare('UPDATE '.$this->tableName.' SET secret = ? WHERE userid = ?'); |
|
| 145 | 145 | } else { |
| 146 | - $sth = $this->handle->prepare('INSERT INTO ' . $this->tableName . ' (secret,userid) VALUES (?,?)'); |
|
| 146 | + $sth = $this->handle->prepare('INSERT INTO '.$this->tableName.' (secret,userid) VALUES (?,?)'); |
|
| 147 | 147 | } |
| 148 | 148 | $sth->execute(array($secret, $userId)); |
| 149 | 149 | } |
@@ -86,8 +86,7 @@ discard block |
||
| 86 | 86 | $sth = $this->handle->prepare('SELECT userid FROM ' . $this->tableName . ' WHERE userid = ?'); |
| 87 | 87 | $sth->execute(array($userId)); |
| 88 | 88 | return (false !== $sth->fetchColumn()); |
| 89 | - } |
|
| 90 | - catch (Exception $e) { |
|
| 89 | + } catch (Exception $e) { |
|
| 91 | 90 | $this->logger->error('PDO error checking user exists', array('exception'=>$e, 'userId'=>$userId)); |
| 92 | 91 | throw ReadWriteException::fromOriginalException($e); |
| 93 | 92 | } |
@@ -111,8 +110,7 @@ discard block |
||
| 111 | 110 | $this->logger->error(sprintf('No result getting secret for user "%s"', $userId)); |
| 112 | 111 | throw new RuntimeException('User not found'); |
| 113 | 112 | } |
| 114 | - } |
|
| 115 | - catch (Exception $e) { |
|
| 113 | + } catch (Exception $e) { |
|
| 116 | 114 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId)); |
| 117 | 115 | throw ReadWriteException::fromOriginalException($e); |
| 118 | 116 | } |
@@ -146,8 +144,7 @@ discard block |
||
| 146 | 144 | $sth = $this->handle->prepare('INSERT INTO ' . $this->tableName . ' (secret,userid) VALUES (?,?)'); |
| 147 | 145 | } |
| 148 | 146 | $sth->execute(array($secret, $userId)); |
| 149 | - } |
|
| 150 | - catch (Exception $e) { |
|
| 147 | + } catch (Exception $e) { |
|
| 151 | 148 | $this->logger->error( |
| 152 | 149 | sprintf('Unable to persist user secret for user "%s" in user secret storage (PDO)', $userId), |
| 153 | 150 | array('exception'=>$e) |
@@ -21,6 +21,6 @@ |
||
| 21 | 21 | public static function fromOriginalException(Exception $e): ReadWriteException |
| 22 | 22 | { |
| 23 | 23 | // $code must be int, otherwise this throws with Error("Wrong parameters for ReadWriteException") |
| 24 | - return new self($e->getMessage(), (int)$e->getCode(), $e ); |
|
| 24 | + return new self($e->getMessage(), (int) $e->getCode(), $e); |
|
| 25 | 25 | } |
| 26 | 26 | } |
@@ -59,7 +59,7 @@ |
||
| 59 | 59 | * @param array $options The options |
| 60 | 60 | * @param LoggerInterface $logger |
| 61 | 61 | */ |
| 62 | - public function __construct(array $options=array(), LoggerInterface $logger) |
|
| 62 | + public function __construct(array $options = array(), LoggerInterface $logger) |
|
| 63 | 63 | { |
| 64 | 64 | $this->_options = $options; |
| 65 | 65 | $this->logger = $logger; |
@@ -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 | } |
@@ -40,7 +40,7 @@ |
||
| 40 | 40 | * |
| 41 | 41 | * @return Tiqr_UserSecretStorage_Encryption_Interface |
| 42 | 42 | */ |
| 43 | - public static function getEncryption(LoggerInterface $logger, string $type="dummy", array $options=array()): Tiqr_UserSecretStorage_Encryption_Interface |
|
| 43 | + public static function getEncryption(LoggerInterface $logger, string $type = "dummy", array $options = array()): Tiqr_UserSecretStorage_Encryption_Interface |
|
| 44 | 44 | { |
| 45 | 45 | $logger->info(sprintf('Using %s as UserStorage encryption type', $type)); |
| 46 | 46 | switch ($type) { |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | public function createUser(string $userId, string $displayName) : void |
| 61 | 61 | { |
| 62 | 62 | $user = array("userId"=>$userId, |
| 63 | - "displayName"=>$displayName); |
|
| 63 | + "displayName"=>$displayName); |
|
| 64 | 64 | $this->_saveUser($userId, $user); |
| 65 | 65 | } |
| 66 | 66 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | { |
| 91 | 91 | if ($data = $this->_loadUser($userId)) { |
| 92 | 92 | if (isset($data["notificationType"])) { |
| 93 | - return $data["notificationType"]; |
|
| 93 | + return $data["notificationType"]; |
|
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | return ''; |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | { |
| 114 | 114 | if ($data = $this->_loadUser($userId)) { |
| 115 | 115 | if (isset($data["notificationAddress"])) { |
| 116 | - return $data["notificationAddress"]; |
|
| 116 | + return $data["notificationAddress"]; |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | $this->logger->info('Unable to find notification address for user'); |
@@ -170,10 +170,10 @@ |
||
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | if ($timestamp + $tempBlockDuration * 60 < time()) { |
| 173 | - return false; // Temp block expired |
|
| 173 | + return false; // Temp block expired |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | - return true; // Blocked by temp block |
|
| 176 | + return true; // Blocked by temp block |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -128,7 +128,7 @@ |
||
| 128 | 128 | * |
| 129 | 129 | * Note that the $tempBlockDuration is specified in MINUTES |
| 130 | 130 | */ |
| 131 | - public function isBlocked(string $userId, int $tempBlockDuration=0): bool; |
|
| 131 | + public function isBlocked(string $userId, int $tempBlockDuration = 0): bool; |
|
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | 134 | * Block or unblock the user account. |
@@ -30,7 +30,6 @@ |
||
| 30 | 30 | notificationtype varchar(10), |
| 31 | 31 | notificationaddress varchar(64) |
| 32 | 32 | ); |
| 33 | - |
|
| 34 | 33 | */ |
| 35 | 34 | |
| 36 | 35 | use Psr\Log\LoggerInterface; |
@@ -82,21 +82,21 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | private function _getStringValue(string $columnName, string $userId): string |
| 84 | 84 | { |
| 85 | - if ( !in_array($columnName, $this->_allowedStringColumns) ) { |
|
| 85 | + if (!in_array($columnName, $this->_allowedStringColumns)) { |
|
| 86 | 86 | throw new InvalidArgumentException('Unsupported column name'); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | try { |
| 90 | - $sth = $this->handle->prepare('SELECT ' . $columnName . ' FROM ' . $this->tablename . ' WHERE userid = ?'); |
|
| 90 | + $sth = $this->handle->prepare('SELECT '.$columnName.' FROM '.$this->tablename.' WHERE userid = ?'); |
|
| 91 | 91 | $sth->execute(array($userId)); |
| 92 | - $res=$sth->fetchColumn(); |
|
| 92 | + $res = $sth->fetchColumn(); |
|
| 93 | 93 | if ($res === false) { |
| 94 | 94 | // No result |
| 95 | 95 | $this->logger->error(sprintf('No result getting "%s" for user "%s"', $columnName, $userId)); |
| 96 | 96 | throw new RuntimeException('User not found'); |
| 97 | 97 | } |
| 98 | 98 | if ($res === NULL) { |
| 99 | - return ''; // Value unset |
|
| 99 | + return ''; // Value unset |
|
| 100 | 100 | } |
| 101 | 101 | if (!is_string($res)) { |
| 102 | 102 | $this->logger->error(sprintf('Expected string type while getting "%s" for user "%s"', $columnName, $userId)); |
@@ -120,28 +120,28 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | private function _getIntValue(string $columnName, string $userId): int |
| 122 | 122 | { |
| 123 | - if ( !in_array($columnName, $this->_allowedIntColumns) ) { |
|
| 123 | + if (!in_array($columnName, $this->_allowedIntColumns)) { |
|
| 124 | 124 | throw new InvalidArgumentException('Unsupported column name'); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | try { |
| 128 | - $sth = $this->handle->prepare('SELECT ' . $columnName . ' FROM ' . $this->tablename . ' WHERE userid = ?'); |
|
| 128 | + $sth = $this->handle->prepare('SELECT '.$columnName.' FROM '.$this->tablename.' WHERE userid = ?'); |
|
| 129 | 129 | $sth->execute(array($userId)); |
| 130 | - $res=$sth->fetchColumn(); |
|
| 130 | + $res = $sth->fetchColumn(); |
|
| 131 | 131 | if ($res === false) { |
| 132 | 132 | // No result |
| 133 | 133 | $this->logger->error(sprintf('No result getting "%s" for user "%s"', $columnName, $userId)); |
| 134 | 134 | throw new RuntimeException('User not found'); |
| 135 | 135 | } |
| 136 | 136 | if ($res === NULL) { |
| 137 | - return 0; // Value unset |
|
| 137 | + return 0; // Value unset |
|
| 138 | 138 | } |
| 139 | 139 | // Return type for integers depends on the PDO driver, can be string |
| 140 | 140 | if (!is_numeric($res)) { |
| 141 | 141 | $this->logger->error(sprintf('Expected int type while getting "%s" for user "%s"', $columnName, $userId)); |
| 142 | 142 | throw new RuntimeException('Unexpected return type'); |
| 143 | 143 | } |
| 144 | - return (int)$res; |
|
| 144 | + return (int) $res; |
|
| 145 | 145 | } |
| 146 | 146 | catch (Exception $e) { |
| 147 | 147 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
@@ -158,11 +158,11 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | private function _setStringValue(string $columnName, string $userId, string $value): void |
| 160 | 160 | { |
| 161 | - if ( !in_array($columnName, $this->_allowedStringColumns) ) { |
|
| 161 | + if (!in_array($columnName, $this->_allowedStringColumns)) { |
|
| 162 | 162 | throw new InvalidArgumentException('Unsupported column name'); |
| 163 | 163 | } |
| 164 | 164 | try { |
| 165 | - $sth = $this->handle->prepare('UPDATE ' . $this->tablename . ' SET ' . $columnName . ' = ? WHERE userid = ?'); |
|
| 165 | + $sth = $this->handle->prepare('UPDATE '.$this->tablename.' SET '.$columnName.' = ? WHERE userid = ?'); |
|
| 166 | 166 | $sth->execute(array($value, $userId)); |
| 167 | 167 | if ($sth->rowCount() == 0) { |
| 168 | 168 | throw new RuntimeException('User not found'); |
@@ -183,11 +183,11 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | private function _setIntValue(string $columnName, string $userId, int $value): void |
| 185 | 185 | { |
| 186 | - if ( !in_array($columnName, $this->_allowedIntColumns) ) { |
|
| 186 | + if (!in_array($columnName, $this->_allowedIntColumns)) { |
|
| 187 | 187 | throw new InvalidArgumentException('Unsupported column name'); |
| 188 | 188 | } |
| 189 | 189 | try { |
| 190 | - $sth = $this->handle->prepare('UPDATE ' . $this->tablename . ' SET ' . $columnName . ' = ? WHERE userid = ?'); |
|
| 190 | + $sth = $this->handle->prepare('UPDATE '.$this->tablename.' SET '.$columnName.' = ? WHERE userid = ?'); |
|
| 191 | 191 | $sth->execute(array($value, $userId)); |
| 192 | 192 | if ($sth->rowCount() == 0) { |
| 193 | 193 | throw new RuntimeException('User not found'); |
@@ -296,17 +296,17 @@ discard block |
||
| 296 | 296 | { |
| 297 | 297 | // Check for blocked |
| 298 | 298 | if ($this->_getIntValue('blocked', $userId) != 0) { |
| 299 | - return true; // Blocked |
|
| 299 | + return true; // Blocked |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | if (0 == $tempBlockDuration) { |
| 303 | - return false; // No check for temporary block |
|
| 303 | + return false; // No check for temporary block |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | // Check for temporary block |
| 307 | 307 | $timestamp = $this->getTemporaryBlockTimestamp($userId); |
| 308 | 308 | // if no temporary block timestamp is set or if the temporary block is expired, return false |
| 309 | - if ( 0 == $timestamp || ($timestamp + $tempBlockDuration * 60) < time()) { |
|
| 309 | + if (0 == $timestamp || ($timestamp + $tempBlockDuration * 60) < time()) { |
|
| 310 | 310 | return false; |
| 311 | 311 | } |
| 312 | 312 | return true; |
@@ -103,8 +103,7 @@ discard block |
||
| 103 | 103 | throw new RuntimeException('Unexpected return type'); |
| 104 | 104 | } |
| 105 | 105 | return $res; |
| 106 | - } |
|
| 107 | - catch (Exception $e) { |
|
| 106 | + } catch (Exception $e) { |
|
| 108 | 107 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
| 109 | 108 | throw ReadWriteException::fromOriginalException($e); |
| 110 | 109 | } |
@@ -142,8 +141,7 @@ discard block |
||
| 142 | 141 | throw new RuntimeException('Unexpected return type'); |
| 143 | 142 | } |
| 144 | 143 | return (int)$res; |
| 145 | - } |
|
| 146 | - catch (Exception $e) { |
|
| 144 | + } catch (Exception $e) { |
|
| 147 | 145 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
| 148 | 146 | throw ReadWriteException::fromOriginalException($e); |
| 149 | 147 | } |
@@ -167,8 +165,7 @@ discard block |
||
| 167 | 165 | if ($sth->rowCount() == 0) { |
| 168 | 166 | throw new RuntimeException('User not found'); |
| 169 | 167 | } |
| 170 | - } |
|
| 171 | - catch (Exception $e) { |
|
| 168 | + } catch (Exception $e) { |
|
| 172 | 169 | $this->logger->error('PDO error updating user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
| 173 | 170 | throw ReadWriteException::fromOriginalException($e); |
| 174 | 171 | } |
@@ -192,8 +189,7 @@ discard block |
||
| 192 | 189 | if ($sth->rowCount() == 0) { |
| 193 | 190 | throw new RuntimeException('User not found'); |
| 194 | 191 | } |
| 195 | - } |
|
| 196 | - catch (Exception $e) { |
|
| 192 | + } catch (Exception $e) { |
|
| 197 | 193 | $this->logger->error('PDO error updating user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
| 198 | 194 | throw ReadWriteException::fromOriginalException($e); |
| 199 | 195 | } |
@@ -210,8 +206,7 @@ discard block |
||
| 210 | 206 | try { |
| 211 | 207 | $sth = $this->handle->prepare("INSERT INTO ".$this->tablename." (displayname,userid) VALUES (?,?)"); |
| 212 | 208 | $sth->execute(array($displayName, $userId)); |
| 213 | - } |
|
| 214 | - catch (Exception $e) { |
|
| 209 | + } catch (Exception $e) { |
|
| 215 | 210 | $this->logger->error(sprintf('Error creating user "%s"', $userId), array('exception'=>$e)); |
| 216 | 211 | throw new ReadWriteException('The user could not be saved in the user storage (PDO)'); |
| 217 | 212 | } |
@@ -226,8 +221,7 @@ discard block |
||
| 226 | 221 | $sth = $this->handle->prepare("SELECT userid FROM ".$this->tablename." WHERE userid = ?"); |
| 227 | 222 | $sth->execute(array($userId)); |
| 228 | 223 | return (false !== $sth->fetchColumn()); |
| 229 | - } |
|
| 230 | - catch (Exception $e) { |
|
| 224 | + } catch (Exception $e) { |
|
| 231 | 225 | $this->logger->error('PDO error checking user exists', array('exception'=>$e, 'userId'=>$userId)); |
| 232 | 226 | throw ReadWriteException::fromOriginalException($e); |
| 233 | 227 | } |