Test Failed
Branch feature/support-php8 (28058b)
by Pieter van der
06:39 queued 02:38
created
library/tiqr/Tiqr/UserSecretStorage/File.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,6 @@
 block discarded – undo
35 35
  * Supported options:
36 36
  * path : Path to the directory where the user data is stored
37 37
  *
38
-
39 38
  */
40 39
 class Tiqr_UserSecretStorage_File implements Tiqr_UserSecretStorage_Interface
41 40
 {
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserSecretStorage/Pdo.php 3 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this 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.
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,6 @@
 block discarded – undo
42 42
     userid varchar(30) NOT NULL UNIQUE,
43 43
     secret varchar(128),
44 44
 );
45
-
46 45
  * @see Tiqr_UserSecretStorage::getSecretStorage()
47 46
  * @see Tiqr_UserSecretStorage_Interface
48 47
  *
Please login to merge, or discard this patch.
library/tiqr/Tiqr/OATH/OCRAParser.php 2 patches
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -4,32 +4,32 @@  discard block
 block discarded – undo
4 4
 
5 5
 class OATH_OCRAParser {
6 6
 
7
-	private $OCRASuite = NULL;
7
+    private $OCRASuite = NULL;
8 8
 
9
-	private $OCRAVersion = NULL;
9
+    private $OCRAVersion = NULL;
10 10
 
11
-	private $CryptoFunctionType = NULL;
12
-	private $CryptoFunctionHash = NULL;
13
-	private $CryptoFunctionHashLength = NULL;
14
-	private $CryptoFunctionTruncation = NULL;
11
+    private $CryptoFunctionType = NULL;
12
+    private $CryptoFunctionHash = NULL;
13
+    private $CryptoFunctionHashLength = NULL;
14
+    private $CryptoFunctionTruncation = NULL;
15 15
 
16
-	private $C = FALSE;
17
-	private $Q = FALSE;
18
-	private $QType = 'N';
19
-	private $QLength = 8;
16
+    private $C = FALSE;
17
+    private $Q = FALSE;
18
+    private $QType = 'N';
19
+    private $QLength = 8;
20 20
 
21
-	private $P = FALSE;
22
-	private $PType = 'SHA1';
23
-	private $PLength = 20;
21
+    private $P = FALSE;
22
+    private $PType = 'SHA1';
23
+    private $PLength = 20;
24 24
 
25
-	private $S = FALSE;
26
-	private $SLength = 64;
25
+    private $S = FALSE;
26
+    private $SLength = 64;
27 27
 
28
-	private $T = FALSE;
29
-	private $TLength = 60; // 1M
30
-	private $TPeriods = array('H' => 3600, 'M' => 60, 'S' => 1);
28
+    private $T = FALSE;
29
+    private $TLength = 60; // 1M
30
+    private $TPeriods = array('H' => 3600, 'M' => 60, 'S' => 1);
31 31
 
32
-	private $supportedHashFunctions = array('SHA1' => 20, 'SHA256' => 32, 'SHA512' => 64);
32
+    private $supportedHashFunctions = array('SHA1' => 20, 'SHA256' => 32, 'SHA512' => 64);
33 33
 
34 34
 
35 35
     /**
@@ -37,149 +37,149 @@  discard block
 block discarded – undo
37 37
      * @throws Exception
38 38
      */
39 39
     public function __construct(String $ocraSuite) {
40
-		$this->parseOCRASuite($ocraSuite);
41
-	}
40
+        $this->parseOCRASuite($ocraSuite);
41
+    }
42 42
 
43
-	/**
44
-	 * Inspired by https://github.com/bdauvergne/python-oath
43
+    /**
44
+     * Inspired by https://github.com/bdauvergne/python-oath
45 45
      *
46 46
      * @throws Exception
47
-	 */
48
-	private function parseOCRASuite($ocraSuite) {
49
-		if (!is_string($ocraSuite)) {
50
-			throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
51
-		}
52
-
53
-		$ocraSuite = strtoupper($ocraSuite);
54
-		$this->OCRASuite = $ocraSuite;
55
-
56
-		$s = explode(':', $ocraSuite);
57
-		if (count($s) != 3) {
58
-			throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
59
-		}
60
-
61
-		$algo = explode('-', $s[0]);
62
-		if (count($algo) != 2) {
63
-			throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
64
-		}
65
-
66
-		if ($algo[0] !== 'OCRA') {
67
-			throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
68
-		}
69
-
70
-		if ($algo[1] !== '1') {
71
-			throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
72
-		}
73
-		$this->OCRAVersion = $algo[1];
74
-
75
-		$cf = explode('-', $s[1]);
76
-		if (count($cf) != 3) {
77
-			throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
78
-		}
79
-
80
-		if ($cf[0] !== 'HOTP') {
81
-			throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
82
-		}
83
-		$this->CryptoFunctionType = $cf[0];
84
-
85
-		if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
86
-			throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
87
-		}
88
-		$this->CryptoFunctionHash = $cf[1];
89
-		$this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
90
-
91
-		if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
92
-			throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
93
-		}
94
-		$this->CryptoFunctionTruncation = intval($cf[2]);
95
-
96
-		$di = explode('-', $s[2]);
97
-		if (count($cf) == 0) {
98
-			throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
99
-		}
100
-
101
-		$data_input = array();
102
-		foreach($di as $elem) {
103
-			$letter = $elem[0];
104
-			if (array_key_exists($letter, $data_input)) {
105
-				throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
106
-			}
107
-			$data_input[$letter] = 1;
108
-
109
-			if ($letter === 'C' && strlen($elem) == 1) {
110
-				$this->C = TRUE;
111
-			} elseif ($letter === 'Q') {
112
-				if (strlen($elem) == 1) {
113
-					$this->Q = TRUE;
114
-				} elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
115
-					$q_len = intval($match[2]);
116
-					if ($q_len < 4 || $q_len > 64) {
117
-						throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
118
-					}
119
-					$this->Q = TRUE;
120
-					$this->QType = $match[1];
121
-					$this->QLength = $q_len;
122
-				} else {
123
-					throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
124
-				}
125
-			} elseif ($letter === 'P') {
126
-				if (strlen($elem) == 1) {
127
-					$this->P = TRUE;
128
-				} else {
129
-					$p_algo = substr($elem, 1);
130
-					if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
131
-						throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
132
-					}
133
-					$this->P = TRUE;
134
-					$this->PType = $p_algo;
135
-					$this->PLength = $this->supportedHashFunctions[$p_algo];
136
-				}
137
-			} elseif ($letter === 'S') {
138
-				if (strlen($elem) == 1) {
139
-					$this->S = TRUE;
140
-				} elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
141
-					$s_len = intval($match[1]);
142
-					if ($s_len <= 0 || $s_len > 512) {
143
-						throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
144
-					}
145
-
146
-					$this->S = TRUE;
147
-					$this->SLength = $s_len;
148
-				} else {
149
-					throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
150
-				}
151
-			} elseif ($letter === 'T') {
152
-				if (strlen($elem) == 1) {
153
-					$this->T = TRUE;
154
-				} elseif (preg_match('/^T(\d+[HMS])+$/', $elem)) {
155
-					preg_match_all('/(\d+)([HMS])/', $elem, $match);
156
-
157
-					if (count($match[1]) !== count(array_unique($match[2]))) {
158
-						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
159
-					}
160
-
161
-					$length = 0;
162
-					for ($i = 0; $i < count($match[1]); $i++) {
163
-						$length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
164
-					}
165
-					if ($length <= 0) {
166
-						throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
167
-					}
168
-
169
-					$this->T = TRUE;
170
-					$this->TLength = $length;
171
-				} else {
172
-					throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
173
-				}
174
-			} else {
175
-				throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
176
-			}
177
-		}
178
-
179
-		if (!$this->Q) {
180
-			throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
181
-		}
182
-	}
47
+     */
48
+    private function parseOCRASuite($ocraSuite) {
49
+        if (!is_string($ocraSuite)) {
50
+            throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
51
+        }
52
+
53
+        $ocraSuite = strtoupper($ocraSuite);
54
+        $this->OCRASuite = $ocraSuite;
55
+
56
+        $s = explode(':', $ocraSuite);
57
+        if (count($s) != 3) {
58
+            throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
59
+        }
60
+
61
+        $algo = explode('-', $s[0]);
62
+        if (count($algo) != 2) {
63
+            throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
64
+        }
65
+
66
+        if ($algo[0] !== 'OCRA') {
67
+            throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
68
+        }
69
+
70
+        if ($algo[1] !== '1') {
71
+            throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
72
+        }
73
+        $this->OCRAVersion = $algo[1];
74
+
75
+        $cf = explode('-', $s[1]);
76
+        if (count($cf) != 3) {
77
+            throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
78
+        }
79
+
80
+        if ($cf[0] !== 'HOTP') {
81
+            throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
82
+        }
83
+        $this->CryptoFunctionType = $cf[0];
84
+
85
+        if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
86
+            throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
87
+        }
88
+        $this->CryptoFunctionHash = $cf[1];
89
+        $this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
90
+
91
+        if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
92
+            throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
93
+        }
94
+        $this->CryptoFunctionTruncation = intval($cf[2]);
95
+
96
+        $di = explode('-', $s[2]);
97
+        if (count($cf) == 0) {
98
+            throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
99
+        }
100
+
101
+        $data_input = array();
102
+        foreach($di as $elem) {
103
+            $letter = $elem[0];
104
+            if (array_key_exists($letter, $data_input)) {
105
+                throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
106
+            }
107
+            $data_input[$letter] = 1;
108
+
109
+            if ($letter === 'C' && strlen($elem) == 1) {
110
+                $this->C = TRUE;
111
+            } elseif ($letter === 'Q') {
112
+                if (strlen($elem) == 1) {
113
+                    $this->Q = TRUE;
114
+                } elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
115
+                    $q_len = intval($match[2]);
116
+                    if ($q_len < 4 || $q_len > 64) {
117
+                        throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
118
+                    }
119
+                    $this->Q = TRUE;
120
+                    $this->QType = $match[1];
121
+                    $this->QLength = $q_len;
122
+                } else {
123
+                    throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
124
+                }
125
+            } elseif ($letter === 'P') {
126
+                if (strlen($elem) == 1) {
127
+                    $this->P = TRUE;
128
+                } else {
129
+                    $p_algo = substr($elem, 1);
130
+                    if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
131
+                        throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
132
+                    }
133
+                    $this->P = TRUE;
134
+                    $this->PType = $p_algo;
135
+                    $this->PLength = $this->supportedHashFunctions[$p_algo];
136
+                }
137
+            } elseif ($letter === 'S') {
138
+                if (strlen($elem) == 1) {
139
+                    $this->S = TRUE;
140
+                } elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
141
+                    $s_len = intval($match[1]);
142
+                    if ($s_len <= 0 || $s_len > 512) {
143
+                        throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
144
+                    }
145
+
146
+                    $this->S = TRUE;
147
+                    $this->SLength = $s_len;
148
+                } else {
149
+                    throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
150
+                }
151
+            } elseif ($letter === 'T') {
152
+                if (strlen($elem) == 1) {
153
+                    $this->T = TRUE;
154
+                } elseif (preg_match('/^T(\d+[HMS])+$/', $elem)) {
155
+                    preg_match_all('/(\d+)([HMS])/', $elem, $match);
156
+
157
+                    if (count($match[1]) !== count(array_unique($match[2]))) {
158
+                        throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
159
+                    }
160
+
161
+                    $length = 0;
162
+                    for ($i = 0; $i < count($match[1]); $i++) {
163
+                        $length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
164
+                    }
165
+                    if ($length <= 0) {
166
+                        throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
167
+                    }
168
+
169
+                    $this->T = TRUE;
170
+                    $this->TLength = $length;
171
+                } else {
172
+                    throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
173
+                }
174
+            } else {
175
+                throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
176
+            }
177
+        }
178
+
179
+        if (!$this->Q) {
180
+            throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
181
+        }
182
+    }
183 183
 
184 184
     /** Generate an OCRA challenge question according to the ocra suite specified in the constructor
185 185
      * @return The randomly generated OCRA question
@@ -192,50 +192,50 @@  discard block
 block discarded – undo
192 192
      * Note that the question string is the exact question string a specified in the OCRA strandard (RFC 6287)
193 193
      * The challenge is not yet hex encoded as expected by OCRA::generateOCRA()
194 194
      */
195
-	public function generateChallenge() : String {
196
-		$q_length = $this->QLength;
197
-		$q_type = $this->QType;
195
+    public function generateChallenge() : String {
196
+        $q_length = $this->QLength;
197
+        $q_type = $this->QType;
198 198
 
199 199
         $bytes = Tiqr_Random::randomBytes($q_length);
200 200
 
201
-		switch($q_type) {
202
-			case 'A':
203
-				$challenge = base64_encode($bytes);
204
-				$tr = implode("", unpack('H*', $bytes));
205
-				$challenge = rtrim(strtr($challenge, '+/', $tr), '=');
206
-				break;
207
-			case 'H':
208
-				$challenge = implode("", unpack('H*', $bytes));
209
-				break;
210
-			case 'N':
211
-				$challenge = implode("", unpack('N*', $bytes));
212
-				break;
213
-			default:
214
-				throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
215
-				break;
216
-		}
217
-
218
-		$challenge = substr($challenge, 0, $q_length);
219
-
220
-		return $challenge;
221
-	}
222
-
223
-
224
-	/**
225
-	 * Constant time string comparison, see http://codahale.com/a-lesson-in-timing-attacks/
226
-	 */
227
-	public static function constEqual(string $s1, string $s2): bool {
228
-		if (strlen($s1) != strlen($s2)) {
229
-			return FALSE;
230
-		}
231
-
232
-		$result = TRUE;
233
-		$length = strlen($s1);
234
-		for ($i = 0; $i < $length; $i++) {
235
-			$result &= ($s1[$i] == $s2[$i]);
236
-		}
237
-
238
-		return (boolean)$result;
239
-	}
201
+        switch($q_type) {
202
+            case 'A':
203
+                $challenge = base64_encode($bytes);
204
+                $tr = implode("", unpack('H*', $bytes));
205
+                $challenge = rtrim(strtr($challenge, '+/', $tr), '=');
206
+                break;
207
+            case 'H':
208
+                $challenge = implode("", unpack('H*', $bytes));
209
+                break;
210
+            case 'N':
211
+                $challenge = implode("", unpack('N*', $bytes));
212
+                break;
213
+            default:
214
+                throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
215
+                break;
216
+        }
217
+
218
+        $challenge = substr($challenge, 0, $q_length);
219
+
220
+        return $challenge;
221
+    }
222
+
223
+
224
+    /**
225
+     * Constant time string comparison, see http://codahale.com/a-lesson-in-timing-attacks/
226
+     */
227
+    public static function constEqual(string $s1, string $s2): bool {
228
+        if (strlen($s1) != strlen($s2)) {
229
+            return FALSE;
230
+        }
231
+
232
+        $result = TRUE;
233
+        $length = strlen($s1);
234
+        for ($i = 0; $i < $length; $i++) {
235
+            $result &= ($s1[$i] == $s2[$i]);
236
+        }
237
+
238
+        return (boolean)$result;
239
+    }
240 240
 
241 241
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	 */
46 46
 	private function parseOCRASuite($ocraSuite) {
47 47
 		if (!is_string($ocraSuite)) {
48
-			throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
48
+			throw new Exception('OCRASuite not in string format: '.var_export($ocraSuite, TRUE));
49 49
 		}
50 50
 
51 51
 		$ocraSuite = strtoupper($ocraSuite);
@@ -53,54 +53,54 @@  discard block
 block discarded – undo
53 53
 
54 54
 		$s = explode(':', $ocraSuite);
55 55
 		if (count($s) != 3) {
56
-			throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
56
+			throw new Exception('Invalid OCRASuite format: '.var_export($ocraSuite, TRUE));
57 57
 		}
58 58
 
59 59
 		$algo = explode('-', $s[0]);
60 60
 		if (count($algo) != 2) {
61
-			throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
61
+			throw new Exception('Invalid OCRA version: '.var_export($s[0], TRUE));
62 62
 		}
63 63
 
64 64
 		if ($algo[0] !== 'OCRA') {
65
-			throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
65
+			throw new Exception('Unsupported OCRA algorithm: '.var_export($algo[0], TRUE));
66 66
 		}
67 67
 
68 68
 		if ($algo[1] !== '1') {
69
-			throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
69
+			throw new Exception('Unsupported OCRA version: '.var_export($algo[1], TRUE));
70 70
 		}
71 71
 		$this->OCRAVersion = $algo[1];
72 72
 
73 73
 		$cf = explode('-', $s[1]);
74 74
 		if (count($cf) != 3) {
75
-			throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
75
+			throw new Exception('Invalid OCRA suite crypto function: '.var_export($s[1], TRUE));
76 76
 		}
77 77
 
78 78
 		if ($cf[0] !== 'HOTP') {
79
-			throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
79
+			throw new Exception('Unsupported OCRA suite crypto function: '.var_export($cf[0], TRUE));
80 80
 		}
81 81
 		$this->CryptoFunctionType = $cf[0];
82 82
 
83 83
 		if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
84
-			throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
84
+			throw new Exception('Unsupported hash function in OCRA suite crypto function: '.var_export($cf[1], TRUE));
85 85
 		}
86 86
 		$this->CryptoFunctionHash = $cf[1];
87 87
 		$this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
88 88
 
89 89
 		if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
90
-			throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
90
+			throw new Exception('Invalid OCRA suite crypto function truncation length: '.var_export($cf[2], TRUE));
91 91
 		}
92 92
 		$this->CryptoFunctionTruncation = intval($cf[2]);
93 93
 
94 94
 		$di = explode('-', $s[2]);
95 95
 		if (count($cf) == 0) {
96
-			throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
96
+			throw new Exception('Invalid OCRA suite data input: '.var_export($s[2], TRUE));
97 97
 		}
98 98
 
99 99
 		$data_input = array();
100
-		foreach($di as $elem) {
100
+		foreach ($di as $elem) {
101 101
 			$letter = $elem[0];
102 102
 			if (array_key_exists($letter, $data_input)) {
103
-				throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
103
+				throw new Exception('Duplicate field in OCRA suite data input: '.var_export($elem, TRUE));
104 104
 			}
105 105
 			$data_input[$letter] = 1;
106 106
 
@@ -112,13 +112,13 @@  discard block
 block discarded – undo
112 112
 				} elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
113 113
 					$q_len = intval($match[2]);
114 114
 					if ($q_len < 4 || $q_len > 64) {
115
-						throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
115
+						throw new Exception('Invalid OCRA suite data input question length: '.var_export($q_len, TRUE));
116 116
 					}
117 117
 					$this->Q = TRUE;
118 118
 					$this->QType = $match[1];
119 119
 					$this->QLength = $q_len;
120 120
 				} else {
121
-					throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
121
+					throw new Exception('Invalid OCRA suite data input question: '.var_export($elem, TRUE));
122 122
 				}
123 123
 			} elseif ($letter === 'P') {
124 124
 				if (strlen($elem) == 1) {
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 				} else {
127 127
 					$p_algo = substr($elem, 1);
128 128
 					if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
129
-						throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
129
+						throw new Exception('Unsupported OCRA suite PIN hash function: '.var_export($elem, TRUE));
130 130
 					}
131 131
 					$this->P = TRUE;
132 132
 					$this->PType = $p_algo;
@@ -138,13 +138,13 @@  discard block
 block discarded – undo
138 138
 				} elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
139 139
 					$s_len = intval($match[1]);
140 140
 					if ($s_len <= 0 || $s_len > 512) {
141
-						throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
141
+						throw new Exception('Invalid OCRA suite data input session information length: '.var_export($s_len, TRUE));
142 142
 					}
143 143
 
144 144
 					$this->S = TRUE;
145 145
 					$this->SLength = $s_len;
146 146
 				} else {
147
-					throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
147
+					throw new Exception('Invalid OCRA suite data input session information length: '.var_export($elem, TRUE));
148 148
 				}
149 149
 			} elseif ($letter === 'T') {
150 150
 				if (strlen($elem) == 1) {
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 					preg_match_all('/(\d+)([HMS])/', $elem, $match);
154 154
 
155 155
 					if (count($match[1]) !== count(array_unique($match[2]))) {
156
-						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
156
+						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: '.var_export($elem, TRUE));
157 157
 					}
158 158
 
159 159
 					$length = 0;
@@ -161,21 +161,21 @@  discard block
 block discarded – undo
161 161
 						$length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
162 162
 					}
163 163
 					if ($length <= 0) {
164
-						throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
164
+						throw new Exception('Invalid OCRA suite data input timestamp: '.var_export($elem, TRUE));
165 165
 					}
166 166
 
167 167
 					$this->T = TRUE;
168 168
 					$this->TLength = $length;
169 169
 				} else {
170
-					throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
170
+					throw new Exception('Invalid OCRA suite data input timestamp: '.var_export($elem, TRUE));
171 171
 				}
172 172
 			} else {
173
-				throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
173
+				throw new Exception('Unsupported OCRA suite data input field: '.var_export($elem, TRUE));
174 174
 			}
175 175
 		}
176 176
 
177 177
 		if (!$this->Q) {
178
-			throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
178
+			throw new Exception('OCRA suite data input question not defined: '.var_export($s[2], TRUE));
179 179
 		}
180 180
 	}
181 181
 
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 
197 197
         $bytes = Tiqr_Random::randomBytes($q_length);
198 198
 
199
-		switch($q_type) {
199
+		switch ($q_type) {
200 200
 			case 'A':
201 201
 				$challenge = base64_encode($bytes);
202 202
 				$tr = implode("", unpack('H*', $bytes));
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 				$challenge = implode("", unpack('N*', $bytes));
210 210
 				break;
211 211
 			default:
212
-				throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
212
+				throw new Exception('Unsupported OCRASuite challenge type: '.var_export($q_type, TRUE));
213 213
 				break;
214 214
 		}
215 215
 
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 			$result &= ($s1[$i] == $s2[$i]);
234 234
 		}
235 235
 
236
-		return (boolean)$result;
236
+		return (boolean) $result;
237 237
 	}
238 238
 
239 239
 }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage/FileTrait.php 2 patches
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.
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/Encryption.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
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) {
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage/GenericStore.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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');
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -170,10 +170,10 @@
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.
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/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.