Passed
Push — develop ( 63c666...4ff015 )
by Pieter van der
16:59
created
library/tiqr/Tiqr/StateStorage/File.php 1 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/OcraService/OathServiceClient.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@
 block discarded – undo
81 81
                     'verifyResponse for user "%s" failed',
82 82
                     $userId
83 83
                 ),
84
-                array( 'exception' => $e)
84
+                array('exception' => $e)
85 85
             );
86 86
             return false;
87 87
         }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/Random.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
     public static function randomBytes(int $length): string
43 43
     {
44 44
         // Get $length cryptographically secure pseudo-random bytes
45
-        $rnd=\random_bytes($length);
45
+        $rnd = \random_bytes($length);
46 46
 
47 47
         if (strlen($rnd) !== $length) {
48 48
             throw new Exception("random_bytes did not return the requested number of bytes");
Please login to merge, or discard this patch.
library/tiqr/Tiqr/Exception/ReadWriteException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,6 +22,6 @@
 block discarded – undo
22 22
     {
23 23
         // $code must be int, otherwise this throws with Error("Wrong parameters for ReadWriteException")
24 24
         // PDOException::getCode() can return a sting
25
-        return new self($e->getMessage(), (int)$e->getCode(), $e );
25
+        return new self($e->getMessage(), (int) $e->getCode(), $e);
26 26
     }
27 27
 }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage/Pdo.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -89,21 +89,21 @@  discard block
 block discarded – undo
89 89
      */
90 90
     private function _getStringValue(string $columnName, string $userId): string
91 91
     {
92
-        if ( !in_array($columnName, $this->_allowedStringColumns) ) {
92
+        if (!in_array($columnName, $this->_allowedStringColumns)) {
93 93
             throw new InvalidArgumentException('Unsupported column name');
94 94
         }
95 95
 
96 96
         try {
97
-            $sth = $this->handle->prepare('SELECT ' . $columnName . ' FROM ' . $this->tablename . ' WHERE userid = ?');
97
+            $sth = $this->handle->prepare('SELECT '.$columnName.' FROM '.$this->tablename.' WHERE userid = ?');
98 98
             $sth->execute(array($userId));
99
-            $res=$sth->fetchColumn();
99
+            $res = $sth->fetchColumn();
100 100
             if ($res === false) {
101 101
                 // No result
102 102
                 $this->logger->error(sprintf('No result getting "%s" for user "%s"', $columnName, $userId));
103 103
                 throw new RuntimeException('User not found');
104 104
             }
105 105
             if ($res === NULL) {
106
-                return '';  // Value unset
106
+                return ''; // Value unset
107 107
             }
108 108
             if (!is_string($res)) {
109 109
                 $this->logger->error(sprintf('Expected string type while getting "%s" for user "%s"', $columnName, $userId));
@@ -127,28 +127,28 @@  discard block
 block discarded – undo
127 127
      */
128 128
     private function _getIntValue(string $columnName, string $userId): int
129 129
     {
130
-        if ( !in_array($columnName, $this->_allowedIntColumns) ) {
130
+        if (!in_array($columnName, $this->_allowedIntColumns)) {
131 131
             throw new InvalidArgumentException('Unsupported column name');
132 132
         }
133 133
 
134 134
         try {
135
-            $sth = $this->handle->prepare('SELECT ' . $columnName . ' FROM ' . $this->tablename . ' WHERE userid = ?');
135
+            $sth = $this->handle->prepare('SELECT '.$columnName.' FROM '.$this->tablename.' WHERE userid = ?');
136 136
             $sth->execute(array($userId));
137
-            $res=$sth->fetchColumn();
137
+            $res = $sth->fetchColumn();
138 138
             if ($res === false) {
139 139
                 // No result
140 140
                 $this->logger->error(sprintf('No result getting "%s" for user "%s"', $columnName, $userId));
141 141
                 throw new RuntimeException('User not found');
142 142
             }
143 143
             if ($res === NULL) {
144
-                return 0;  // Value unset
144
+                return 0; // Value unset
145 145
             }
146 146
             // Return type for integers depends on the PDO driver, can be string
147 147
             if (!is_numeric($res)) {
148 148
                 $this->logger->error(sprintf('Expected int type while getting "%s" for user "%s"', $columnName, $userId));
149 149
                 throw new RuntimeException('Unexpected return type');
150 150
             }
151
-            return (int)$res;
151
+            return (int) $res;
152 152
         }
153 153
         catch (Exception $e) {
154 154
             $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName));
@@ -165,11 +165,11 @@  discard block
 block discarded – undo
165 165
      */
166 166
     private function _setStringValue(string $columnName, string $userId, string $value): void
167 167
     {
168
-        if ( !in_array($columnName, $this->_allowedStringColumns) ) {
168
+        if (!in_array($columnName, $this->_allowedStringColumns)) {
169 169
             throw new InvalidArgumentException('Unsupported column name');
170 170
         }
171 171
         try {
172
-            $sth = $this->handle->prepare('UPDATE ' . $this->tablename . ' SET ' . $columnName . ' = ? WHERE userid = ?');
172
+            $sth = $this->handle->prepare('UPDATE '.$this->tablename.' SET '.$columnName.' = ? WHERE userid = ?');
173 173
             $sth->execute(array($value, $userId));
174 174
             if ($sth->rowCount() == 0) {
175 175
                 // Required for mysql which only returns the number of rows that were actually updated
@@ -193,11 +193,11 @@  discard block
 block discarded – undo
193 193
      */
194 194
     private function _setIntValue(string $columnName, string $userId, int $value): void
195 195
     {
196
-        if ( !in_array($columnName, $this->_allowedIntColumns) ) {
196
+        if (!in_array($columnName, $this->_allowedIntColumns)) {
197 197
             throw new InvalidArgumentException('Unsupported column name');
198 198
         }
199 199
         try {
200
-            $sth = $this->handle->prepare('UPDATE ' . $this->tablename . ' SET ' . $columnName . ' = ? WHERE userid = ?');
200
+            $sth = $this->handle->prepare('UPDATE '.$this->tablename.' SET '.$columnName.' = ? WHERE userid = ?');
201 201
             $sth->execute(array($value, $userId));
202 202
             if ($sth->rowCount() == 0) {
203 203
                 // Required for mysql which only returns the number of rows that were actually updated
@@ -309,17 +309,17 @@  discard block
 block discarded – undo
309 309
     {
310 310
         // Check for blocked
311 311
         if ($this->_getIntValue('blocked', $userId) != 0) {
312
-            return true;   // Blocked
312
+            return true; // Blocked
313 313
         }
314 314
 
315 315
         if (0 == $tempBlockDuration) {
316
-            return false;   // No check for temporary block
316
+            return false; // No check for temporary block
317 317
         }
318 318
 
319 319
         // Check for temporary block
320 320
         $timestamp = $this->getTemporaryBlockTimestamp($userId);
321 321
         // if no temporary block timestamp is set or if the temporary block is expired, return false
322
-        if ( 0 == $timestamp || ($timestamp + $tempBlockDuration * 60) < time()) {
322
+        if (0 == $timestamp || ($timestamp + $tempBlockDuration * 60) < time()) {
323 323
             return false;
324 324
         }
325 325
         return true;
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserSecretStorage.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
                 $password = $options['password'];
75 75
 
76 76
                 try {
77
-                    $handle = new PDO($dsn, $userName, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) );
77
+                    $handle = new PDO($dsn, $userName, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
78 78
                 } catch (PDOException $e) {
79 79
                     $logger->error(
80 80
                         sprintf('Unable to establish a PDO connection. Error message from PDO: %s', $e->getMessage())
Please login to merge, or discard this patch.
library/tiqr/Tiqr/OcraService.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,10 +39,10 @@
 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=null)
42
+    public static function getOcraService(string $type = "tiqr", array $options = array(), LoggerInterface $logger = null)
43 43
     {
44 44
         if (!$logger)
45
-            $logger=new \Psr\Log\NullLogger();
45
+            $logger = new \Psr\Log\NullLogger();
46 46
 
47 47
         switch ($type) {
48 48
             case "tiqr":
Please login to merge, or discard this patch.
library/tiqr/Tiqr/OATH/OCRAParser.php 1 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.