Test Failed
Pull Request — develop (#27)
by Michiel
06:54
created
library/tiqr/OATH/OCRAParser.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once ( __DIR__ . "/../Tiqr/Random.php");
3
+require_once (__DIR__."/../Tiqr/Random.php");
4 4
 
5 5
 class OATH_OCRAParser {
6 6
 
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 */
44 44
 	private function parseOCRASuite($ocraSuite) {
45 45
 		if (!is_string($ocraSuite)) {
46
-			throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
46
+			throw new Exception('OCRASuite not in string format: '.var_export($ocraSuite, TRUE));
47 47
 		}
48 48
 
49 49
 		$ocraSuite = strtoupper($ocraSuite);
@@ -51,54 +51,54 @@  discard block
 block discarded – undo
51 51
 
52 52
 		$s = explode(':', $ocraSuite);
53 53
 		if (count($s) != 3) {
54
-			throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
54
+			throw new Exception('Invalid OCRASuite format: '.var_export($ocraSuite, TRUE));
55 55
 		}
56 56
 
57 57
 		$algo = explode('-', $s[0]);
58 58
 		if (count($algo) != 2) {
59
-			throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
59
+			throw new Exception('Invalid OCRA version: '.var_export($s[0], TRUE));
60 60
 		}
61 61
 
62 62
 		if ($algo[0] !== 'OCRA') {
63
-			throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
63
+			throw new Exception('Unsupported OCRA algorithm: '.var_export($algo[0], TRUE));
64 64
 		}
65 65
 
66 66
 		if ($algo[1] !== '1') {
67
-			throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
67
+			throw new Exception('Unsupported OCRA version: '.var_export($algo[1], TRUE));
68 68
 		}
69 69
 		$this->OCRAVersion = $algo[1];
70 70
 
71 71
 		$cf = explode('-', $s[1]);
72 72
 		if (count($cf) != 3) {
73
-			throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
73
+			throw new Exception('Invalid OCRA suite crypto function: '.var_export($s[1], TRUE));
74 74
 		}
75 75
 
76 76
 		if ($cf[0] !== 'HOTP') {
77
-			throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
77
+			throw new Exception('Unsupported OCRA suite crypto function: '.var_export($cf[0], TRUE));
78 78
 		}
79 79
 		$this->CryptoFunctionType = $cf[0];
80 80
 
81 81
 		if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
82
-			throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
82
+			throw new Exception('Unsupported hash function in OCRA suite crypto function: '.var_export($cf[1], TRUE));
83 83
 		}
84 84
 		$this->CryptoFunctionHash = $cf[1];
85 85
 		$this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
86 86
 
87 87
 		if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
88
-			throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
88
+			throw new Exception('Invalid OCRA suite crypto function truncation length: '.var_export($cf[2], TRUE));
89 89
 		}
90 90
 		$this->CryptoFunctionTruncation = intval($cf[2]);
91 91
 
92 92
 		$di = explode('-', $s[2]);
93 93
 		if (count($cf) == 0) {
94
-			throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
94
+			throw new Exception('Invalid OCRA suite data input: '.var_export($s[2], TRUE));
95 95
 		}
96 96
 
97 97
 		$data_input = array();
98
-		foreach($di as $elem) {
98
+		foreach ($di as $elem) {
99 99
 			$letter = $elem[0];
100 100
 			if (array_key_exists($letter, $data_input)) {
101
-				throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
101
+				throw new Exception('Duplicate field in OCRA suite data input: '.var_export($elem, TRUE));
102 102
 			}
103 103
 			$data_input[$letter] = 1;
104 104
 
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 				} elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
111 111
 					$q_len = intval($match[2]);
112 112
 					if ($q_len < 4 || $q_len > 64) {
113
-						throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
113
+						throw new Exception('Invalid OCRA suite data input question length: '.var_export($q_len, TRUE));
114 114
 					}
115 115
 					$this->Q = TRUE;
116 116
 					$this->QType = $match[1];
117 117
 					$this->QLength = $q_len;
118 118
 				} else {
119
-					throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
119
+					throw new Exception('Invalid OCRA suite data input question: '.var_export($elem, TRUE));
120 120
 				}
121 121
 			} elseif ($letter === 'P') {
122 122
 				if (strlen($elem) == 1) {
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 				} else {
125 125
 					$p_algo = substr($elem, 1);
126 126
 					if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
127
-						throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
127
+						throw new Exception('Unsupported OCRA suite PIN hash function: '.var_export($elem, TRUE));
128 128
 					}
129 129
 					$this->P = TRUE;
130 130
 					$this->PType = $p_algo;
@@ -136,13 +136,13 @@  discard block
 block discarded – undo
136 136
 				} elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
137 137
 					$s_len = intval($match[1]);
138 138
 					if ($s_len <= 0 || $s_len > 512) {
139
-						throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
139
+						throw new Exception('Invalid OCRA suite data input session information length: '.var_export($s_len, TRUE));
140 140
 					}
141 141
 
142 142
 					$this->S = TRUE;
143 143
 					$this->SLength = $s_len;
144 144
 				} else {
145
-					throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
145
+					throw new Exception('Invalid OCRA suite data input session information length: '.var_export($elem, TRUE));
146 146
 				}
147 147
 			} elseif ($letter === 'T') {
148 148
 				if (strlen($elem) == 1) {
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 					preg_match_all('/(\d+)([HMS])/', $elem, $match);
152 152
 
153 153
 					if (count($match[1]) !== count(array_unique($match[2]))) {
154
-						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
154
+						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: '.var_export($elem, TRUE));
155 155
 					}
156 156
 
157 157
 					$length = 0;
@@ -159,21 +159,21 @@  discard block
 block discarded – undo
159 159
 						$length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
160 160
 					}
161 161
 					if ($length <= 0) {
162
-						throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
162
+						throw new Exception('Invalid OCRA suite data input timestamp: '.var_export($elem, TRUE));
163 163
 					}
164 164
 
165 165
 					$this->T = TRUE;
166 166
 					$this->TLength = $length;
167 167
 				} else {
168
-					throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
168
+					throw new Exception('Invalid OCRA suite data input timestamp: '.var_export($elem, TRUE));
169 169
 				}
170 170
 			} else {
171
-				throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
171
+				throw new Exception('Unsupported OCRA suite data input field: '.var_export($elem, TRUE));
172 172
 			}
173 173
 		}
174 174
 
175 175
 		if (!$this->Q) {
176
-			throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
176
+			throw new Exception('OCRA suite data input question not defined: '.var_export($s[2], TRUE));
177 177
 		}
178 178
 	}
179 179
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 
184 184
         $bytes = Tiqr_Random::randomBytes($q_length);
185 185
 
186
-		switch($q_type) {
186
+		switch ($q_type) {
187 187
 			case 'A':
188 188
 				$challenge = base64_encode($bytes);
189 189
 				$tr = implode("", unpack('H*', $bytes));
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 				$challenge = implode("", unpack('N*', $bytes));
197 197
 				break;
198 198
 			default:
199
-				throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
199
+				throw new Exception('Unsupported OCRASuite challenge type: '.var_export($q_type, TRUE));
200 200
 				break;
201 201
 		}
202 202
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 
209 209
 	public function generateSessionInformation() {
210 210
 		if (!$this->S) {
211
-			throw new Exception('Session information not defined in OCRASuite: ' . var_export($this->OCRASuite, TRUE));
211
+			throw new Exception('Session information not defined in OCRASuite: '.var_export($this->OCRASuite, TRUE));
212 212
 		}
213 213
 
214 214
 		$s_length = $this->SLength;
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 			$result &= ($s1[$i] == $s2[$i]);
239 239
 		}
240 240
 
241
-		return (boolean)$result;
241
+		return (boolean) $result;
242 242
 	}
243 243
 
244 244
 }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/OATH/OCRAWrapper_v1.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      */
64 64
     public function generateSessionKey() 
65 65
     {
66
-        return bin2hex( Tiqr_Random::randomBytes(self::SESSIONKEY_SIZE) );
66
+        return bin2hex(Tiqr_Random::randomBytes(self::SESSIONKEY_SIZE));
67 67
     }
68 68
     
69 69
     /**
@@ -107,19 +107,19 @@  discard block
 block discarded – undo
107 107
     {
108 108
         // find the :QN10, -QN10, QH10 etc. bit
109 109
         $pos = stripos($ocraSuite, ":q");
110
-        if ($pos===false) $pos = stripos($ocraSuite, "-q");
111
-        if ($pos===false) {
110
+        if ($pos === false) $pos = stripos($ocraSuite, "-q");
111
+        if ($pos === false) {
112 112
             // No challenge config specified. Since we only support challenge based OCRA, we fallback to default 10 digit hexadecimal.
113 113
             return array("format"=>"H", "length"=>10);
114 114
         }
115
-        $format = substr($ocraSuite, $pos+2, 1);
115
+        $format = substr($ocraSuite, $pos + 2, 1);
116 116
         if (!in_array($format, array("N", "A", "H"))) {
117 117
             $format = "H";
118 118
         }
119 119
         
120
-        $length = (int)substr($ocraSuite, $pos+3, 2);
120
+        $length = (int) substr($ocraSuite, $pos + 3, 2);
121 121
                 
122
-        if ($length<=0) {
122
+        if ($length <= 0) {
123 123
             $length = 10;
124 124
         }
125 125
         
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
      */
191 191
     protected function _calculateResponse($ocraSuite, $secret, $challenge, $sessionKey)
192 192
     {       
193
-        if (strpos(strtolower($ocraSuite), "qn")!==false) {
193
+        if (strpos(strtolower($ocraSuite), "qn") !== false) {
194 194
             
195 195
             // challenge is decimal, but generateOcra always wants it in hex.
196 196
             $challenge = dechex($challenge);
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
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
     public static function randomBytes($length)
40 40
     {
41 41
         // Get $length cryptographically secure pseudo-random bytes
42
-        $rnd=\random_bytes($length);
42
+        $rnd = \random_bytes($length);
43 43
 
44 44
         if (strlen($rnd) !== $length) {
45 45
             throw new Exception("random_bytes did not return the requested number of bytes");
Please login to merge, or discard this patch.
library/tiqr/Tiqr/DeviceStorage/TokenExchange.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,15 +41,15 @@
 block discarded – undo
41 41
     {
42 42
         $url = $this->_options["url"]."?appId=".$this->_options["appid"];
43 43
         
44
-        $url.= "&notificationToken=".$notificationToken;
44
+        $url .= "&notificationToken=".$notificationToken;
45 45
         
46 46
         $output = file_get_contents($url);
47
-        if (stripos($output, "not found")!==false) {
47
+        if (stripos($output, "not found") !== false) {
48 48
             $this->logger->error('Token Exchange failed and responded with: not found', ['full output' => $output]);
49 49
             return false;
50 50
         }
51 51
 
52
-        if (stripos($output, "error")!==false) {
52
+        if (stripos($output, "error") !== false) {
53 53
             $this->logger->error('Token Exchange failed and responded with: error', ['full output' => $output]);
54 54
             return false;
55 55
         }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/DeviceStorage/Abstract.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@
 block discarded – undo
58 58
      * the Tiqr_DeviceStorage factory will call this for you.
59 59
      * @param array $options The options for the s
60 60
      */
61
-    public function __construct($options=array(), LoggerInterface $logger)
61
+    public function __construct($options = array(), LoggerInterface $logger)
62 62
     {
63 63
         $this->_options = $options;
64 64
         $this->logger = $logger;
Please login to merge, or discard this patch.
library/tiqr/Tiqr/StateStorage/Memcache.php 1 patch
Spacing   +2 added lines, -2 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.
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      * (non-PHPdoc)
103 103
      * @see library/tiqr/Tiqr/StateStorage/Tiqr_StateStorage_Abstract::setValue()
104 104
      */
105
-    public function setValue($key, $value, $expire=0)
105
+    public function setValue($key, $value, $expire = 0)
106 106
     {  
107 107
         $key = $this->_getKeyPrefix().$key;
108 108
 
Please login to merge, or discard this patch.
library/tiqr/Tiqr/StateStorage/File.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      * (non-PHPdoc)
37 37
      * @see library/tiqr/Tiqr/StateStorage/Tiqr_StateStorage_Abstract::setValue()
38 38
      */
39
-    public function setValue($key, $value, $expire=0)
39
+    public function setValue($key, $value, $expire = 0)
40 40
     {   
41 41
         $envelope = array("expire"=>$expire,
42 42
                           "createdAt"=>time(),
@@ -71,9 +71,9 @@  discard block
 block discarded – undo
71 71
         $filename = $this->_stateFilename($key);
72 72
         if (file_exists($filename)) {
73 73
             $envelope = unserialize(file_get_contents($filename));
74
-            if ($envelope["expire"]!=0) {
74
+            if ($envelope["expire"] != 0) {
75 75
                  // This data is time-limited. If it's too old we discard it.
76
-                 if (time()-$envelope["createdAt"] > $envelope["expire"]) {
76
+                 if (time() - $envelope["createdAt"] > $envelope["expire"]) {
77 77
                      $this->unsetValue($key);
78 78
                      $this->logger->error('Unable to retrieve the state storage value, it is expired');
79 79
                      return NULL;
Please login to merge, or discard this patch.
library/tiqr/Tiqr/StateStorage/Pdo.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 
72 72
     private function cleanExpired() {
73 73
         $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `expire` < ? AND NOT `expire` = 0");
74
-        if (!$sth->execute(array(time()))){
74
+        if (!$sth->execute(array(time()))) {
75 75
             $this->logger->error('Unable to remove expired keys from the pdo state storage');
76 76
         }
77 77
     }
@@ -80,9 +80,9 @@  discard block
 block discarded – undo
80 80
      * (non-PHPdoc)
81 81
      * @see library/tiqr/Tiqr/StateStorage/Tiqr_StateStorage_Abstract::setValue()
82 82
      */
83
-    public function setValue($key, $value, $expire=0)
83
+    public function setValue($key, $value, $expire = 0)
84 84
     {
85
-        if (((float) rand() /(float) getrandmax()) < $this->cleanupProbability) {
85
+        if (((float) rand() / (float) getrandmax()) < $this->cleanupProbability) {
86 86
             $this->cleanExpired();
87 87
         }
88 88
         if ($this->keyExists($key)) {
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
         }
93 93
         // $expire == 0 means never expire
94 94
         if ($expire != 0) {
95
-            $expire+=time();    // Store unix timestamp after which the expires
95
+            $expire += time(); // Store unix timestamp after which the expires
96 96
         }
97
-        $sth->execute(array(serialize($value),$expire,$key));
97
+        $sth->execute(array(serialize($value), $expire, $key));
98 98
     }
99 99
         
100 100
     /**
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
                 $this->logger->error('Unable to prepare the get key statement');
122 122
                 return NULL;
123 123
             }
124
-            if (false === $sth->execute(array($key, time())) ) {
124
+            if (false === $sth->execute(array($key, time()))) {
125 125
                 $this->logger->error('Unable to get key from the pdo state storage');
126 126
                 return NULL;
127 127
             }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/StateStorage/Abstract.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      * @param mixed $value The data to store in state storage
48 48
      * @param int $expire The expiration (in seconds) of the data
49 49
      */
50
-    public abstract function setValue($key, $value, $expire=0);
50
+    public abstract function setValue($key, $value, $expire = 0);
51 51
     
52 52
     /**
53 53
      * Remove a value from the state storage
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      * a state storage instance of a certain type.
82 82
      * @param array $options An array of options for the state storage
83 83
      */
84
-    public function __construct($options=array(), LoggerInterface $logger)
84
+    public function __construct($options = array(), LoggerInterface $logger)
85 85
     {
86 86
         $this->logger = $logger;
87 87
         $this->_options = $options;        
Please login to merge, or discard this patch.