@@ -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. |
@@ -29,7 +29,7 @@ |
||
29 | 29 | * @throws ReadWriteException |
30 | 30 | * @throws Exception |
31 | 31 | */ |
32 | - public function setValue(string $key, $value, int $expire=0): void; |
|
32 | + public function setValue(string $key, $value, int $expire = 0): void; |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * Remove $key from the state storage |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | /** |
48 | 48 | * @see Tiqr_StateStorage_StateStorageInterface::setValue() |
49 | 49 | */ |
50 | - public function setValue(string $key, $value, int $expire=0): void |
|
50 | + public function setValue(string $key, $value, int $expire = 0): void |
|
51 | 51 | { |
52 | 52 | if (empty($key)) { |
53 | 53 | throw new InvalidArgumentException('Empty key not allowed'); |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | |
110 | 110 | private function getPath(): string |
111 | 111 | { |
112 | - if (substr($this->path, -1)!=="/") { |
|
113 | - return $this->path . "/"; |
|
112 | + if (substr($this->path, -1) !== "/") { |
|
113 | + return $this->path."/"; |
|
114 | 114 | } |
115 | 115 | return $this->path; |
116 | 116 | } |
@@ -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. |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | /** |
104 | 104 | * @see Tiqr_StateStorage_StateStorageInterface::setValue() |
105 | 105 | */ |
106 | - public function setValue(string $key, $value, int $expire=0): void |
|
106 | + public function setValue(string $key, $value, int $expire = 0): void |
|
107 | 107 | { |
108 | 108 | if (empty($key)) { |
109 | 109 | throw new InvalidArgumentException('Empty key not allowed'); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | if ($result === false) { |
158 | 158 | // Memcache interface does not provide error information, either the key does not exists or |
159 | 159 | // there was an error communicating with the memcache |
160 | - $this->logger->info( sprintf('Unable to get key "%s" from memcache StateStorage', $key) ); |
|
160 | + $this->logger->info(sprintf('Unable to get key "%s" from memcache StateStorage', $key)); |
|
161 | 161 | return null; |
162 | 162 | } |
163 | 163 | return $result; |
@@ -81,7 +81,7 @@ |
||
81 | 81 | 'verifyResponse for user "%s" failed', |
82 | 82 | $userId |
83 | 83 | ), |
84 | - array( 'exception' => $e) |
|
84 | + array('exception' => $e) |
|
85 | 85 | ); |
86 | 86 | return false; |
87 | 87 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | public static function randomBytes(int $length): string |
43 | 43 | { |
44 | 44 | // Get $length cryptographically secure pseudo-random bytes |
45 | - $rnd=\random_bytes($length); |
|
45 | + $rnd = \random_bytes($length); |
|
46 | 46 | |
47 | 47 | if (strlen($rnd) !== $length) { |
48 | 48 | throw new Exception("random_bytes did not return the requested number of bytes"); |
@@ -22,6 +22,6 @@ |
||
22 | 22 | { |
23 | 23 | // $code must be int, otherwise this throws with Error("Wrong parameters for ReadWriteException") |
24 | 24 | // PDOException::getCode() can return a sting |
25 | - return new self($e->getMessage(), (int)$e->getCode(), $e ); |
|
25 | + return new self($e->getMessage(), (int) $e->getCode(), $e); |
|
26 | 26 | } |
27 | 27 | } |
@@ -89,21 +89,21 @@ discard block |
||
89 | 89 | */ |
90 | 90 | private function _getStringValue(string $columnName, string $userId): string |
91 | 91 | { |
92 | - if ( !in_array($columnName, $this->_allowedStringColumns) ) { |
|
92 | + if (!in_array($columnName, $this->_allowedStringColumns)) { |
|
93 | 93 | throw new InvalidArgumentException('Unsupported column name'); |
94 | 94 | } |
95 | 95 | |
96 | 96 | try { |
97 | - $sth = $this->handle->prepare('SELECT ' . $columnName . ' FROM ' . $this->tablename . ' WHERE userid = ?'); |
|
97 | + $sth = $this->handle->prepare('SELECT '.$columnName.' FROM '.$this->tablename.' WHERE userid = ?'); |
|
98 | 98 | $sth->execute(array($userId)); |
99 | - $res=$sth->fetchColumn(); |
|
99 | + $res = $sth->fetchColumn(); |
|
100 | 100 | if ($res === false) { |
101 | 101 | // No result |
102 | 102 | $this->logger->error(sprintf('No result getting "%s" for user "%s"', $columnName, $userId)); |
103 | 103 | throw new RuntimeException('User not found'); |
104 | 104 | } |
105 | 105 | if ($res === NULL) { |
106 | - return ''; // Value unset |
|
106 | + return ''; // Value unset |
|
107 | 107 | } |
108 | 108 | if (!is_string($res)) { |
109 | 109 | $this->logger->error(sprintf('Expected string type while getting "%s" for user "%s"', $columnName, $userId)); |
@@ -127,28 +127,28 @@ discard block |
||
127 | 127 | */ |
128 | 128 | private function _getIntValue(string $columnName, string $userId): int |
129 | 129 | { |
130 | - if ( !in_array($columnName, $this->_allowedIntColumns) ) { |
|
130 | + if (!in_array($columnName, $this->_allowedIntColumns)) { |
|
131 | 131 | throw new InvalidArgumentException('Unsupported column name'); |
132 | 132 | } |
133 | 133 | |
134 | 134 | try { |
135 | - $sth = $this->handle->prepare('SELECT ' . $columnName . ' FROM ' . $this->tablename . ' WHERE userid = ?'); |
|
135 | + $sth = $this->handle->prepare('SELECT '.$columnName.' FROM '.$this->tablename.' WHERE userid = ?'); |
|
136 | 136 | $sth->execute(array($userId)); |
137 | - $res=$sth->fetchColumn(); |
|
137 | + $res = $sth->fetchColumn(); |
|
138 | 138 | if ($res === false) { |
139 | 139 | // No result |
140 | 140 | $this->logger->error(sprintf('No result getting "%s" for user "%s"', $columnName, $userId)); |
141 | 141 | throw new RuntimeException('User not found'); |
142 | 142 | } |
143 | 143 | if ($res === NULL) { |
144 | - return 0; // Value unset |
|
144 | + return 0; // Value unset |
|
145 | 145 | } |
146 | 146 | // Return type for integers depends on the PDO driver, can be string |
147 | 147 | if (!is_numeric($res)) { |
148 | 148 | $this->logger->error(sprintf('Expected int type while getting "%s" for user "%s"', $columnName, $userId)); |
149 | 149 | throw new RuntimeException('Unexpected return type'); |
150 | 150 | } |
151 | - return (int)$res; |
|
151 | + return (int) $res; |
|
152 | 152 | } |
153 | 153 | catch (Exception $e) { |
154 | 154 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
@@ -165,11 +165,11 @@ discard block |
||
165 | 165 | */ |
166 | 166 | private function _setStringValue(string $columnName, string $userId, string $value): void |
167 | 167 | { |
168 | - if ( !in_array($columnName, $this->_allowedStringColumns) ) { |
|
168 | + if (!in_array($columnName, $this->_allowedStringColumns)) { |
|
169 | 169 | throw new InvalidArgumentException('Unsupported column name'); |
170 | 170 | } |
171 | 171 | try { |
172 | - $sth = $this->handle->prepare('UPDATE ' . $this->tablename . ' SET ' . $columnName . ' = ? WHERE userid = ?'); |
|
172 | + $sth = $this->handle->prepare('UPDATE '.$this->tablename.' SET '.$columnName.' = ? WHERE userid = ?'); |
|
173 | 173 | $sth->execute(array($value, $userId)); |
174 | 174 | if ($sth->rowCount() == 0) { |
175 | 175 | // Required for mysql which only returns the number of rows that were actually updated |
@@ -193,11 +193,11 @@ discard block |
||
193 | 193 | */ |
194 | 194 | private function _setIntValue(string $columnName, string $userId, int $value): void |
195 | 195 | { |
196 | - if ( !in_array($columnName, $this->_allowedIntColumns) ) { |
|
196 | + if (!in_array($columnName, $this->_allowedIntColumns)) { |
|
197 | 197 | throw new InvalidArgumentException('Unsupported column name'); |
198 | 198 | } |
199 | 199 | try { |
200 | - $sth = $this->handle->prepare('UPDATE ' . $this->tablename . ' SET ' . $columnName . ' = ? WHERE userid = ?'); |
|
200 | + $sth = $this->handle->prepare('UPDATE '.$this->tablename.' SET '.$columnName.' = ? WHERE userid = ?'); |
|
201 | 201 | $sth->execute(array($value, $userId)); |
202 | 202 | if ($sth->rowCount() == 0) { |
203 | 203 | // Required for mysql which only returns the number of rows that were actually updated |
@@ -309,17 +309,17 @@ discard block |
||
309 | 309 | { |
310 | 310 | // Check for blocked |
311 | 311 | if ($this->_getIntValue('blocked', $userId) != 0) { |
312 | - return true; // Blocked |
|
312 | + return true; // Blocked |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | if (0 == $tempBlockDuration) { |
316 | - return false; // No check for temporary block |
|
316 | + return false; // No check for temporary block |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | // Check for temporary block |
320 | 320 | $timestamp = $this->getTemporaryBlockTimestamp($userId); |
321 | 321 | // if no temporary block timestamp is set or if the temporary block is expired, return false |
322 | - if ( 0 == $timestamp || ($timestamp + $tempBlockDuration * 60) < time()) { |
|
322 | + if (0 == $timestamp || ($timestamp + $tempBlockDuration * 60) < time()) { |
|
323 | 323 | return false; |
324 | 324 | } |
325 | 325 | return true; |