Passed
Pull Request — develop (#41)
by Pieter van der
03:08
created
library/tiqr/Tiqr/OATH/OCRA.php 1 patch
Braces   +42 added lines, -28 removed lines patch added patch discarded remove patch
@@ -122,12 +122,15 @@  discard block
 block discarded – undo
122 122
         $cryptoFunction = $components[1];
123 123
         $dataInput = strtolower($components[2]); // lower here so we can do case insensitive comparisons
124 124
         
125
-        if(stripos($cryptoFunction, "sha1")!==false)
126
-            $crypto = "sha1";
127
-        if(stripos($cryptoFunction, "sha256")!==false)
128
-            $crypto = "sha256";
129
-        if(stripos($cryptoFunction, "sha512")!==false)
130
-            $crypto = "sha512";
125
+        if(stripos($cryptoFunction, "sha1")!==false) {
126
+                    $crypto = "sha1";
127
+        }
128
+        if(stripos($cryptoFunction, "sha256")!==false) {
129
+                    $crypto = "sha256";
130
+        }
131
+        if(stripos($cryptoFunction, "sha512")!==false) {
132
+                    $crypto = "sha512";
133
+        }
131 134
         
132 135
         $codeDigits = substr($cryptoFunction, strrpos($cryptoFunction, "-")+1);
133 136
                 
@@ -135,56 +138,65 @@  discard block
 block discarded – undo
135 138
         // Counter
136 139
         if($dataInput[0] == "c" ) {
137 140
             // Fix the length of the HEX string
138
-            while(strlen($counter) < 16)
139
-                $counter = "0" . $counter;
141
+            while(strlen($counter) < 16) {
142
+                            $counter = "0" . $counter;
143
+            }
140 144
             $counterLength=8;
141 145
         }
142 146
         // Question
143 147
         if($dataInput[0] == "q" ||
144 148
                 stripos($dataInput, "-q")!==false) {
145
-            while(strlen($question) < 256)
146
-                $question = $question . "0";
149
+            while(strlen($question) < 256) {
150
+                            $question = $question . "0";
151
+            }
147 152
             $questionLength=128;
148 153
         }
149 154
 
150 155
         // Password
151 156
         if(stripos($dataInput, "psha1")!==false) {
152
-            while(strlen($password) < 40)
153
-                $password = "0" . $password;
157
+            while(strlen($password) < 40) {
158
+                            $password = "0" . $password;
159
+            }
154 160
             $passwordLength=20;
155 161
         }
156 162
     
157 163
         if(stripos($dataInput, "psha256")!==false) {
158
-            while(strlen($password) < 64)
159
-                $password = "0" . $password;
164
+            while(strlen($password) < 64) {
165
+                            $password = "0" . $password;
166
+            }
160 167
             $passwordLength=32;
161 168
         }
162 169
         
163 170
         if(stripos($dataInput, "psha512")!==false) {
164
-            while(strlen($password) < 128)
165
-                $password = "0" . $password;
171
+            while(strlen($password) < 128) {
172
+                            $password = "0" . $password;
173
+            }
166 174
             $passwordLength=64;
167 175
         }
168 176
         
169 177
         // sessionInformation
170 178
         if(stripos($dataInput, "s064") !==false) {
171
-            while(strlen($sessionInformation) < 128)
172
-                $sessionInformation = "0" . $sessionInformation;
179
+            while(strlen($sessionInformation) < 128) {
180
+                            $sessionInformation = "0" . $sessionInformation;
181
+            }
173 182
 
174 183
             $sessionInformationLength=64;
175 184
         } else if(stripos($dataInput, "s128") !==false) {
176
-            while(strlen($sessionInformation) < 256)
177
-                $sessionInformation = "0" . $sessionInformation;
185
+            while(strlen($sessionInformation) < 256) {
186
+                            $sessionInformation = "0" . $sessionInformation;
187
+            }
178 188
         
179 189
             $sessionInformationLength=128;
180 190
         } else if(stripos($dataInput, "s256") !==false) {
181
-            while(strlen($sessionInformation) < 512)
182
-                $sessionInformation = "0" . $sessionInformation;
191
+            while(strlen($sessionInformation) < 512) {
192
+                            $sessionInformation = "0" . $sessionInformation;
193
+            }
183 194
         
184 195
             $sessionInformationLength=256;
185 196
         } else if(stripos($dataInput, "s512") !==false) {
186
-            while(strlen($sessionInformation) < 128)
187
-                $sessionInformation = "0" . $sessionInformation;
197
+            while(strlen($sessionInformation) < 128) {
198
+                            $sessionInformation = "0" . $sessionInformation;
199
+            }
188 200
         
189 201
             $sessionInformationLength=64;
190 202
         } else if (stripos($dataInput, "-s") !== false ) {
@@ -196,8 +208,9 @@  discard block
 block discarded – undo
196 208
             // to prevent matching the "s" in the password input e.g. "psha1".
197 209
             // [C] | QFxx | [PH | Snnn | TG] : Challenge-Response computation
198 210
             // [C] | QFxx | [PH | TG] : Plain Signature computation
199
-            while(strlen($sessionInformation) < 128)
200
-                $sessionInformation = "0" . $sessionInformation;
211
+            while(strlen($sessionInformation) < 128) {
212
+                            $sessionInformation = "0" . $sessionInformation;
213
+            }
201 214
             
202 215
             $sessionInformationLength=64;
203 216
         }
@@ -207,8 +220,9 @@  discard block
 block discarded – undo
207 220
         // TimeStamp
208 221
         if($dataInput[0] == "t" ||
209 222
                 stripos($dataInput, "-t") !== false) {
210
-            while(strlen($timeStamp) < 16)
211
-                $timeStamp = "0" . $timeStamp;
223
+            while(strlen($timeStamp) < 16) {
224
+                            $timeStamp = "0" . $timeStamp;
225
+            }
212 226
             $timeStampLength=8;
213 227
         }
214 228
 
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserSecretStorage/Pdo.php 1 patch
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -86,8 +86,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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)
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage/FileTrait.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -74,7 +74,9 @@
 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)!="/") {
78
+            return $this->path."/";
79
+        }
78 80
         return $this->path;
79 81
     }
80 82
 }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage/Pdo.php 1 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/Pdo.php 1 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/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.
library/tiqr/Tiqr/Service.php 1 patch
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -263,8 +263,7 @@  discard block
 block discarded – undo
263 263
         if (isset($options['ocraservice']) && $options['ocraservice']['type'] != 'tiqr') {
264 264
             $options['ocraservice']['ocra.suite'] = $this->_ocraSuite;
265 265
             $this->_ocraService = Tiqr_OcraService::getOcraService($options['ocraservice']['type'], $options['ocraservice'], $logger);
266
-        }
267
-        else { // Create default ocraservice
266
+        } else { // Create default ocraservice
268 267
             $this->_ocraService = Tiqr_OcraService::getOcraService('tiqr', array('ocra.suite' => $this->_ocraSuite), $logger);
269 268
         }
270 269
     }
@@ -487,7 +486,9 @@  discard block
 block discarded – undo
487 486
             $sessionId = session_id(); 
488 487
         }
489 488
         $status = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT_STATUS.$sessionId);
490
-        if (is_null($status)) return self::ENROLLMENT_STATUS_IDLE;
489
+        if (is_null($status)) {
490
+            return self::ENROLLMENT_STATUS_IDLE;
491
+        }
491 492
         return $status;
492 493
     }
493 494
         
@@ -843,8 +844,7 @@  discard block
 block discarded – undo
843 844
         
844 845
         try {
845 846
             return $this->_stateStorage->getValue("authenticated_".$sessionId);
846
-        }
847
-        catch (Exception $e) {
847
+        } catch (Exception $e) {
848 848
             $this->logger->error('getAuthenticatedUser failed', array('exception'=>$e));
849 849
             return NULL;
850 850
         }
Please login to merge, or discard this patch.