| Conditions | 29 |
| Paths | 16384 |
| Total Lines | 137 |
| Code Lines | 70 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 85 | static function generateOCRA($ocraSuite, |
||
| 86 | $key, |
||
| 87 | $counter, |
||
| 88 | $question, |
||
| 89 | $password, |
||
| 90 | $sessionInformation, |
||
| 91 | $timeStamp) |
||
| 92 | { |
||
| 93 | $codeDigits = 0; |
||
| 94 | $crypto = ""; |
||
| 95 | $result = null; |
||
| 96 | $ocraSuiteLength = strlen($ocraSuite); |
||
| 97 | $counterLength = 0; |
||
| 98 | $questionLength = 0; |
||
| 99 | $passwordLength = 0; |
||
| 100 | |||
| 101 | $sessionInformationLength = 0; |
||
| 102 | $timeStampLength = 0; |
||
| 103 | |||
| 104 | if(stripos($ocraSuite, "sha1")!==false) |
||
| 105 | $crypto = "sha1"; |
||
| 106 | if(stripos($ocraSuite, "sha256")!==false) |
||
| 107 | $crypto = "sha256"; |
||
| 108 | if(stripos($ocraSuite, "sha512")!==false) |
||
| 109 | $crypto = "sha512"; |
||
| 110 | |||
| 111 | // How many digits should we return |
||
| 112 | $oS = substr($ocraSuite, strpos($ocraSuite, ":")+1, strpos($ocraSuite, ":", strpos($ocraSuite, ":")+1) -strpos($ocraSuite, ":")-1); |
||
| 113 | $codeDigits = substr($oS, strrpos($oS, "-")+1); |
||
| 114 | |||
| 115 | // The size of the byte array message to be encrypted |
||
| 116 | // Counter |
||
| 117 | if(stripos($ocraSuite, ":c") !==false) { |
||
| 118 | // Fix the length of the HEX string |
||
| 119 | while(strlen($counter) < 16) |
||
| 120 | $counter = "0" . $counter; |
||
| 121 | $counterLength=8; |
||
| 122 | } |
||
| 123 | // Question |
||
| 124 | if(stripos($ocraSuite, ":q")!==false || |
||
| 125 | stripos($ocraSuite, "-q")!==false) { |
||
| 126 | while(strlen($question) < 256) |
||
| 127 | $question = $question . "0"; |
||
| 128 | $questionLength=128; |
||
| 129 | } |
||
| 130 | |||
| 131 | // Password |
||
| 132 | if(stripos($ocraSuite, ":p")!==false || |
||
| 133 | stripos($ocraSuite, "-p") !==false) { |
||
| 134 | while(strlen($password) < 40) |
||
| 135 | $password = "0" . $password; |
||
| 136 | $passwordLength=20; |
||
| 137 | } |
||
| 138 | |||
| 139 | // sessionInformation |
||
| 140 | if(stripos($ocraSuite, ":s") !==false || |
||
| 141 | stripos($ocraSuite, "-s", strpos($ocraSuite, ":", strpos($ocraSuite, ":")+1)) !== false) { |
||
| 142 | while(strlen($sessionInformation) < 128) |
||
| 143 | $sessionInformation = "0" . $sessionInformation; |
||
| 144 | |||
| 145 | $sessionInformationLength=64; |
||
| 146 | } |
||
| 147 | |||
| 148 | // TimeStamp |
||
| 149 | if(stripos($ocraSuite, ":t") !==false || |
||
| 150 | stripos($ocraSuite, "-t") !== false) { |
||
| 151 | while(strlen($timeStamp) < 16) |
||
| 152 | $timeStamp = "0" . $timeStamp; |
||
| 153 | $timeStampLength=8; |
||
| 154 | } |
||
| 155 | |||
| 156 | // Put the bytes of "ocraSuite" parameters into the message |
||
| 157 | |||
| 158 | $msg = array_fill(0,$ocraSuiteLength+$counterLength+$questionLength+$passwordLength+$sessionInformationLength+$timeStampLength+1, 0); |
||
| 159 | |||
| 160 | for($i=0;$i<strlen($ocraSuite);$i++) { |
||
| 161 | $msg[$i] = $ocraSuite[$i]; |
||
| 162 | } |
||
| 163 | |||
| 164 | // Delimiter |
||
| 165 | $msg[strlen($ocraSuite)] = self::_hexStr2Bytes("0"); |
||
| 166 | |||
| 167 | // Put the bytes of "Counter" to the message |
||
| 168 | // Input is HEX encoded |
||
| 169 | if($counterLength > 0 ) { |
||
| 170 | $bArray = self::_hexStr2Bytes($counter); |
||
| 171 | for ($i=0;$i<strlen($bArray);$i++) { |
||
| 172 | $msg [$i + $ocraSuiteLength + 1] = $bArray[$i]; |
||
| 173 | } |
||
| 174 | } |
||
| 175 | |||
| 176 | |||
| 177 | // Put the bytes of "question" to the message |
||
| 178 | // Input is text encoded |
||
| 179 | if($questionLength > 0 ) { |
||
| 180 | $bArray = self::_hexStr2Bytes($question); |
||
| 181 | for ($i=0;$i<strlen($bArray);$i++) { |
||
| 182 | $msg [$i + $ocraSuiteLength + 1 + $counterLength] = $bArray[$i]; |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | // Put the bytes of "password" to the message |
||
| 187 | // Input is HEX encoded |
||
| 188 | if($passwordLength > 0){ |
||
| 189 | $bArray = self::_hexStr2Bytes($password); |
||
| 190 | for ($i=0;$i<strlen($bArray);$i++) { |
||
| 191 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength] = $bArray[$i]; |
||
| 192 | } |
||
| 193 | } |
||
| 194 | |||
| 195 | // Put the bytes of "sessionInformation" to the message |
||
| 196 | // Input is text encoded |
||
| 197 | if($sessionInformationLength > 0 ){ |
||
| 198 | $bArray = self::_hexStr2Bytes($sessionInformation); |
||
| 199 | for ($i=0;$i<strlen($bArray);$i++) { |
||
| 200 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength] = $bArray[$i]; |
||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | // Put the bytes of "time" to the message |
||
| 205 | // Input is text value of minutes |
||
| 206 | if($timeStampLength > 0){ |
||
| 207 | $bArray = self::_hexStr2Bytes($timestamp); |
||
| 208 | for ($i=0;$i<strlen($bArray);$i++) { |
||
| 209 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength + $sessionInformationLength] = $bArray[$i]; |
||
| 210 | } |
||
| 211 | } |
||
| 212 | |||
| 213 | $byteKey = self::_hexStr2Bytes($key); |
||
| 214 | |||
| 215 | $msg = implode("", $msg); |
||
| 216 | |||
| 217 | $hash = self::_hmac_sha1($crypto, $byteKey, $msg); |
||
| 218 | |||
| 219 | $result = self::_oath_truncate($hash, $codeDigits); |
||
| 220 | |||
| 221 | return $result; |
||
| 222 | } |
||
| 249 |
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