Conditions | 39 |
Paths | > 20000 |
Total Lines | 174 |
Code Lines | 94 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
76 | static function generateOCRA($ocraSuite, |
||
77 | $key, |
||
78 | $counter, |
||
79 | $question, |
||
80 | $password, |
||
81 | $sessionInformation, |
||
82 | $timeStamp) |
||
83 | { |
||
84 | $codeDigits = 0; |
||
85 | $crypto = ""; |
||
86 | $result = null; |
||
87 | $ocraSuiteLength = strlen($ocraSuite); |
||
88 | $counterLength = 0; |
||
89 | $questionLength = 0; |
||
90 | $passwordLength = 0; |
||
91 | |||
92 | $sessionInformationLength = 0; |
||
93 | $timeStampLength = 0; |
||
94 | |||
95 | // How many digits should we return |
||
96 | $components = explode(":", $ocraSuite); |
||
97 | $cryptoFunction = $components[1]; |
||
98 | $dataInput = strtolower($components[2]); // lower here so we can do case insensitive comparisons |
||
99 | |||
100 | if(stripos($cryptoFunction, "sha1")!==false) |
||
101 | $crypto = "sha1"; |
||
102 | if(stripos($cryptoFunction, "sha256")!==false) |
||
103 | $crypto = "sha256"; |
||
104 | if(stripos($cryptoFunction, "sha512")!==false) |
||
105 | $crypto = "sha512"; |
||
106 | |||
107 | $codeDigits = substr($cryptoFunction, strrpos($cryptoFunction, "-")+1); |
||
108 | |||
109 | // The size of the byte array message to be encrypted |
||
110 | // Counter |
||
111 | if($dataInput[0] == "c" ) { |
||
112 | // Fix the length of the HEX string |
||
113 | while(strlen($counter) < 16) |
||
114 | $counter = "0" . $counter; |
||
115 | $counterLength=8; |
||
116 | } |
||
117 | // Question |
||
118 | if($dataInput[0] == "q" || |
||
119 | stripos($dataInput, "-q")!==false) { |
||
120 | while(strlen($question) < 256) |
||
121 | $question = $question . "0"; |
||
122 | $questionLength=128; |
||
123 | } |
||
124 | |||
125 | // Password |
||
126 | if(stripos($dataInput, "psha1")!==false) { |
||
127 | while(strlen($password) < 40) |
||
128 | $password = "0" . $password; |
||
129 | $passwordLength=20; |
||
130 | } |
||
131 | |||
132 | if(stripos($dataInput, "psha256")!==false) { |
||
133 | while(strlen($password) < 64) |
||
134 | $password = "0" . $password; |
||
135 | $passwordLength=32; |
||
136 | } |
||
137 | |||
138 | if(stripos($dataInput, "psha512")!==false) { |
||
139 | while(strlen($password) < 128) |
||
140 | $password = "0" . $password; |
||
141 | $passwordLength=64; |
||
142 | } |
||
143 | |||
144 | // sessionInformation |
||
145 | if(stripos($dataInput, "s064") !==false) { |
||
146 | while(strlen($sessionInformation) < 128) |
||
147 | $sessionInformation = "0" . $sessionInformation; |
||
148 | |||
149 | $sessionInformationLength=64; |
||
150 | } else if(stripos($dataInput, "s128") !==false) { |
||
151 | while(strlen($sessionInformation) < 256) |
||
152 | $sessionInformation = "0" . $sessionInformation; |
||
153 | |||
154 | $sessionInformationLength=128; |
||
155 | } else if(stripos($dataInput, "s256") !==false) { |
||
156 | while(strlen($sessionInformation) < 512) |
||
157 | $sessionInformation = "0" . $sessionInformation; |
||
158 | |||
159 | $sessionInformationLength=256; |
||
160 | } else if(stripos($dataInput, "s512") !==false) { |
||
161 | while(strlen($sessionInformation) < 128) |
||
162 | $sessionInformation = "0" . $sessionInformation; |
||
163 | |||
164 | $sessionInformationLength=64; |
||
165 | } else if (stripos($dataInput, "s") !== false ) { |
||
166 | // deviation from spec. Officially 's' without a length indicator is not in the reference implementation. |
||
167 | // RFC is ambigious. However we have supported this in Tiqr since day 1, so we continue to support it. |
||
168 | while(strlen($sessionInformation) < 128) |
||
169 | $sessionInformation = "0" . $sessionInformation; |
||
170 | |||
171 | $sessionInformationLength=64; |
||
172 | } |
||
173 | |||
174 | |||
175 | |||
176 | // TimeStamp |
||
177 | if($dataInput[0] == "t" || |
||
178 | stripos($dataInput, "-t") !== false) { |
||
179 | while(strlen($timeStamp) < 16) |
||
180 | $timeStamp = "0" . $timeStamp; |
||
181 | $timeStampLength=8; |
||
182 | } |
||
183 | |||
184 | // Put the bytes of "ocraSuite" parameters into the message |
||
185 | |||
186 | $msg = array_fill(0,$ocraSuiteLength+$counterLength+$questionLength+$passwordLength+$sessionInformationLength+$timeStampLength+1, 0); |
||
187 | |||
188 | for($i=0;$i<strlen($ocraSuite);$i++) { |
||
189 | $msg[$i] = $ocraSuite[$i]; |
||
190 | } |
||
191 | |||
192 | // Delimiter |
||
193 | $msg[strlen($ocraSuite)] = self::_hexStr2Bytes("0"); |
||
194 | |||
195 | // Put the bytes of "Counter" to the message |
||
196 | // Input is HEX encoded |
||
197 | if($counterLength > 0 ) { |
||
198 | $bArray = self::_hexStr2Bytes($counter); |
||
199 | for ($i=0;$i<strlen($bArray);$i++) { |
||
200 | $msg [$i + $ocraSuiteLength + 1] = $bArray[$i]; |
||
201 | } |
||
202 | } |
||
203 | |||
204 | |||
205 | // Put the bytes of "question" to the message |
||
206 | // Input is text encoded |
||
207 | if($questionLength > 0 ) { |
||
208 | $bArray = self::_hexStr2Bytes($question); |
||
209 | for ($i=0;$i<strlen($bArray);$i++) { |
||
210 | $msg [$i + $ocraSuiteLength + 1 + $counterLength] = $bArray[$i]; |
||
211 | } |
||
212 | } |
||
213 | |||
214 | // Put the bytes of "password" to the message |
||
215 | // Input is HEX encoded |
||
216 | if($passwordLength > 0){ |
||
217 | $bArray = self::_hexStr2Bytes($password); |
||
218 | for ($i=0;$i<strlen($bArray);$i++) { |
||
219 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength] = $bArray[$i]; |
||
220 | } |
||
221 | } |
||
222 | |||
223 | // Put the bytes of "sessionInformation" to the message |
||
224 | // Input is text encoded |
||
225 | if($sessionInformationLength > 0 ){ |
||
226 | $bArray = self::_hexStr2Bytes($sessionInformation); |
||
227 | for ($i=0;$i<strlen($bArray);$i++) { |
||
228 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength] = $bArray[$i]; |
||
229 | } |
||
230 | } |
||
231 | |||
232 | // Put the bytes of "time" to the message |
||
233 | // Input is text value of minutes |
||
234 | if($timeStampLength > 0){ |
||
235 | $bArray = self::_hexStr2Bytes($timeStamp); |
||
236 | for ($i=0;$i<strlen($bArray);$i++) { |
||
237 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength + $sessionInformationLength] = $bArray[$i]; |
||
238 | } |
||
239 | } |
||
240 | |||
241 | $byteKey = self::_hexStr2Bytes($key); |
||
242 | |||
243 | $msg = implode("", $msg); |
||
244 | |||
245 | $hash = self::_hmac_sha1($crypto, $byteKey, $msg); |
||
246 | |||
247 | $result = self::_oath_truncate($hash, $codeDigits); |
||
248 | |||
249 | return $result; |
||
250 | } |
||
278 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths