Passed
Pull Request — develop (#41)
by Pieter van der
03:36
created
library/tiqr/Tiqr/UserStorage/Interface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -128,7 +128,7 @@
 block discarded – undo
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.
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage/Pdo.php 3 patches
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,6 @@
 block discarded – undo
30 30
     notificationtype varchar(10),
31 31
     notificationaddress varchar(64)
32 32
 );
33
-
34 33
  */
35 34
 
36 35
 use Psr\Log\LoggerInterface;
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -82,21 +82,21 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -103,8 +103,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/StateStorage/StateStorageInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
library/tiqr/Tiqr/StateStorage/File.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -54,8 +54,8 @@
 block discarded – undo
54 54
         }
55 55
 
56 56
         $envelope = array("expire"=>$expire,
57
-                          "createdAt"=>time(),
58
-                          "value"=>$value);
57
+                            "createdAt"=>time(),
58
+                            "value"=>$value);
59 59
         $filename = $this->getFilenameByKey($key);
60 60
         
61 61
         if (!file_put_contents($filename, serialize($envelope))) {
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/StateStorage/Memcache.php 1 patch
Spacing   +3 added lines, -3 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.
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
library/tiqr/Tiqr/StateStorage/Pdo.php 3 patches
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,6 @@
 block discarded – undo
21 21
  * 
22 22
  * 
23 23
  * Create SQL table (MySQL):
24
-
25 24
  * CREATE TABLE IF NOT EXISTS tiqrstate (
26 25
     key varchar(255) PRIMARY KEY,
27 26
     expire BIGINT,
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
             throw new InvalidArgumentException('Empty key not allowed');
78 78
         }
79 79
         try {
80
-            $sth = $this->handle->prepare('SELECT `key` FROM ' . $this->tablename . ' WHERE `key` = ?');
80
+            $sth = $this->handle->prepare('SELECT `key` FROM '.$this->tablename.' WHERE `key` = ?');
81 81
             $sth->execute(array($key));
82 82
             return $sth->fetchColumn() !== false;
83 83
         }
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
      */
98 98
     private function cleanExpired(): void {
99 99
         try {
100
-            $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `expire` < ? AND NOT `expire` = 0");
100
+            $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `expire` < ? AND NOT `expire` = 0");
101 101
             $sth->execute(array(time()));
102
-            $deletedRows=$sth->rowCount();
102
+            $deletedRows = $sth->rowCount();
103 103
             $this->logger->notice(
104 104
                 sprintf("Deleted %i expired keys", $deletedRows)
105 105
             );
@@ -115,12 +115,12 @@  discard block
 block discarded – undo
115 115
     /**
116 116
      * @see Tiqr_StateStorage_StateStorageInterface::setValue()
117 117
      */
118
-    public function setValue(string $key, $value, int $expire=0): void
118
+    public function setValue(string $key, $value, int $expire = 0): void
119 119
     {
120 120
         if (empty($key)) {
121 121
             throw new InvalidArgumentException('Empty key not allowed');
122 122
         }
123
-        if (((float) rand() /(float) getrandmax()) < $this->cleanupProbability) {
123
+        if (((float) rand() / (float) getrandmax()) < $this->cleanupProbability) {
124 124
             $this->cleanExpired();
125 125
         }
126 126
         if ($this->keyExists($key)) {
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
         }
131 131
         // $expire == 0 means never expire
132 132
         if ($expire != 0) {
133
-            $expire+=time();    // Store unix timestamp after which the expires
133
+            $expire += time(); // Store unix timestamp after which the expires
134 134
         }
135 135
         try {
136 136
             $sth->execute(array(serialize($value), $expire, $key));
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
             throw new InvalidArgumentException('Empty key not allowed');
154 154
         }
155 155
         try {
156
-            $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?");
156
+            $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `key` = ?");
157 157
             $sth->execute(array($key));
158 158
         }
159 159
         catch (Exception $e) {
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
         }
184 184
 
185 185
         try {
186
-            $sth = $this->handle->prepare('SELECT `value` FROM ' . $this->tablename . ' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)');
186
+            $sth = $this->handle->prepare('SELECT `value` FROM '.$this->tablename.' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)');
187 187
             $sth->execute(array($key, time()));
188 188
         }
189 189
         catch (Exception $e) {
@@ -197,9 +197,9 @@  discard block
 block discarded – undo
197 197
         if (false === $result) {
198 198
             // Occurs normally
199 199
             $this->logger->info(sprintf('getValue: Key "%s" not found in PDO StateStorage', $key));
200
-            return NULL;    // Key not found
200
+            return NULL; // Key not found
201 201
         }
202
-        $result=unserialize($result, array('allowed_classes' => false));
202
+        $result = unserialize($result, array('allowed_classes' => false));
203 203
         if (false === $result) {
204 204
             throw new RuntimeException(sprintf('getValue: unserialize error for key "%s" in PDO StateStorage', $key));
205 205
         }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -80,8 +80,7 @@  discard block
 block discarded – undo
80 80
             $sth = $this->handle->prepare('SELECT `key` FROM ' . $this->tablename . ' WHERE `key` = ?');
81 81
             $sth->execute(array($key));
82 82
             return $sth->fetchColumn() !== false;
83
-        }
84
-        catch (Exception $e) {
83
+        } catch (Exception $e) {
85 84
             $this->logger->error(
86 85
                 sprintf('Error checking for key "%s" in PDO StateStorage', $key),
87 86
                 array('exception' => $e)
@@ -103,8 +102,7 @@  discard block
 block discarded – undo
103 102
             $this->logger->notice(
104 103
                 sprintf("Deleted %i expired keys", $deletedRows)
105 104
             );
106
-        }
107
-        catch (Exception $e) {
105
+        } catch (Exception $e) {
108 106
             $this->logger->error(
109 107
                 sprintf("Deleting expired keys failed: %s", $e->getMessage()),
110 108
                 array('exception', $e)
@@ -134,8 +132,7 @@  discard block
 block discarded – undo
134 132
         }
135 133
         try {
136 134
             $sth->execute(array(serialize($value), $expire, $key));
137
-        }
138
-        catch (Exception $e) {
135
+        } catch (Exception $e) {
139 136
             $this->logger->error(
140 137
                 sprintf('Unable to store key "%s" in PDO StateStorage', $key),
141 138
                 array('exception' => $e)
@@ -155,8 +152,7 @@  discard block
 block discarded – undo
155 152
         try {
156 153
             $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?");
157 154
             $sth->execute(array($key));
158
-        }
159
-        catch (Exception $e) {
155
+        } catch (Exception $e) {
160 156
             $this->logger->error(
161 157
                 sprintf('Error deleting key "%s" from PDO StateStorage', $key),
162 158
                 array('exception' => $e)
@@ -185,8 +181,7 @@  discard block
 block discarded – undo
185 181
         try {
186 182
             $sth = $this->handle->prepare('SELECT `value` FROM ' . $this->tablename . ' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)');
187 183
             $sth->execute(array($key, time()));
188
-        }
189
-        catch (Exception $e) {
184
+        } catch (Exception $e) {
190 185
             $this->logger->error(
191 186
                 sprintf('Error getting value for key "%s" from PDO StateStorage', $key),
192 187
                 array('exception' => $e)
Please login to merge, or discard this patch.
library/tiqr/Tiqr/OcraService.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
      * @return Tiqr_OcraService_Interface
40 40
      * @throws Exception An exception if an unknown orca service type is requested.
41 41
      */
42
-    public static function getOcraService(string $type="tiqr", array $options=array(), LoggerInterface $logger)
42
+    public static function getOcraService(string $type = "tiqr", array $options = array(), LoggerInterface $logger)
43 43
     {
44 44
         switch ($type) {
45 45
             case "tiqr":
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
      *
42 42
      * @throws Exception An exception if an unknown user storage is requested.
43 43
      */
44
-    public static function getStorage(string $type="file", array $options=array(), LoggerInterface $logger): Tiqr_UserStorage_Interface
44
+    public static function getStorage(string $type = "file", array $options = array(), LoggerInterface $logger): Tiqr_UserStorage_Interface
45 45
     {
46 46
         switch ($type) {
47 47
             case "file":
Please login to merge, or discard this patch.
library/tiqr/Tiqr/OcraService/Tiqr.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,8 +36,7 @@
 block discarded – undo
36 36
         // response as the client calculated.
37 37
         try {
38 38
             $expected = OCRA::generateOCRA($this->_ocraSuite, $userSecret, "", $challenge, "", $sessionInformation, "");
39
-        }
40
-        catch (Exception $e) {
39
+        } catch (Exception $e) {
41 40
             $this->logger->warning(sprintf('Error calculating OCRA response for user "%s"', $userId), array('exception'=>$e));
42 41
             return false;
43 42
         }
Please login to merge, or discard this patch.