Passed
Push — develop ( afb057...0a569b )
by Pieter van der
01:05 queued 14s
created
library/tiqr/Tiqr/StateStorage/Pdo.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -117,9 +117,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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) {
Please login to merge, or discard this patch.
library/tiqr/Tiqr/StateStorage/Memcache.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
library/tiqr/Tiqr/StateStorage/Abstract.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -71,6 +71,6 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage/Pdo.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -98,21 +98,21 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage/FileTrait.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserSecretStorage/File.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@
 block discarded – undo
80 80
      */
81 81
     protected function setUserSecret(string $userId, string $secret): void
82 82
     {
83
-        $data=array();
83
+        $data = array();
84 84
         if ($this->_userExists($userId)) {
85 85
             $data = $this->_loadUser($userId);
86 86
         }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserSecretStorage/Pdo.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
     public function userExists(string $userId): bool
88 88
     {
89 89
         try {
90
-            $sth = $this->handle->prepare('SELECT userid FROM ' . $this->tableName . ' WHERE userid = ?');
90
+            $sth = $this->handle->prepare('SELECT userid FROM '.$this->tableName.' WHERE userid = ?');
91 91
             $sth->execute(array($userId));
92 92
             return (false !== $sth->fetchColumn());
93 93
         }
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
     protected function getUserSecret(string $userId): string
108 108
     {
109 109
         try {
110
-            $sth = $this->handle->prepare('SELECT secret FROM ' . $this->tableName . ' WHERE userid = ?');
110
+            $sth = $this->handle->prepare('SELECT secret FROM '.$this->tableName.' WHERE userid = ?');
111 111
             $sth->execute(array($userId));
112
-            $res=$sth->fetchColumn();
112
+            $res = $sth->fetchColumn();
113 113
             if ($res === false) {
114 114
                 // No result
115 115
                 $this->logger->error(sprintf('No result getting secret for user "%s"', $userId));
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
         // - The INSERT will fail when displayname has a NOT NULL constraint
146 146
         try {
147 147
             if ($this->userExists($userId)) {
148
-                $sth = $this->handle->prepare('UPDATE ' . $this->tableName . ' SET secret = ? WHERE userid = ?');
148
+                $sth = $this->handle->prepare('UPDATE '.$this->tableName.' SET secret = ? WHERE userid = ?');
149 149
             } else {
150
-                $sth = $this->handle->prepare('INSERT INTO ' . $this->tableName . ' (secret,userid) VALUES (?,?)');
150
+                $sth = $this->handle->prepare('INSERT INTO '.$this->tableName.' (secret,userid) VALUES (?,?)');
151 151
             }
152 152
             $sth->execute(array($secret, $userId));
153 153
         }
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
             $sth->execute();
172 172
         }
173 173
         catch (Exception $e) {
174
-            $statusMessage = "UserSecretStorage_PDO error: " . $e->getMessage();
174
+            $statusMessage = "UserSecretStorage_PDO error: ".$e->getMessage();
175 175
             return false;
176 176
         }
177 177
 
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserSecretStorage/Abstract.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
         if ($prefix === $this->encryption->get_type()) {
58 58
             // Decrypt the secret if it is prefixed with the current encryption type
59 59
             // Remove the encryption type prefix before decrypting
60
-            return $this->encryption->decrypt( substr($encryptedSecret, $pos+1) );
60
+            return $this->encryption->decrypt(substr($encryptedSecret, $pos + 1));
61 61
         }
62 62
 
63 63
         // Check the decryption array for the encryption type to see if there is an encryption
64 64
         // instance defined for it. If so, use that to decrypt the secret.
65 65
         if (isset($this->decryption[$prefix])) {
66
-            return $this->decryption[$prefix]->decrypt( substr($encryptedSecret, $pos+1) );
66
+            return $this->decryption[$prefix]->decrypt(substr($encryptedSecret, $pos + 1));
67 67
         }
68 68
 
69 69
         $this->logger->error("Secret for user '$userId' is encrypted with unsupported encryption type '$prefix'");
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     {
81 81
         $encryptedSecret = $this->encryption->encrypt($secret);
82 82
         // Prefix the user secret with the encryption type
83
-        $this->setUserSecret($userId, $this->encryption->get_type() . ':' . $encryptedSecret);
83
+        $this->setUserSecret($userId, $this->encryption->get_type().':'.$encryptedSecret);
84 84
     }
85 85
 
86 86
     /**
@@ -88,6 +88,6 @@  discard block
 block discarded – undo
88 88
      */
89 89
     public function healthCheck(string &$statusMessage = ''): bool
90 90
     {
91
-        return true;    // Health check is always successful when not implemented
91
+        return true; // Health check is always successful when not implemented
92 92
     }
93 93
 }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage/Abstract.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -71,6 +71,6 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.