| Conditions | 5 |
| Paths | 8 |
| Total Lines | 18 |
| Code Lines | 15 |
| Lines | 2 |
| Ratio | 11.11 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 0 | ||
| 1 | <?php |
||
| 6 | function uhash($num, $len = 10, $base = 36) |
||
| 7 | { |
||
| 8 | $golden_primes = array( |
||
| 9 | 36 => array(1, 23, 809, 28837, 1038073, 37370257, 1345328833) |
||
| 10 | ); |
||
| 11 | $gp = $golden_primes[$base]; |
||
| 12 | $maxlen = count($gp); |
||
| 13 | $len = $len > ($maxlen - 1) ? ($maxlen - 1) : $len; |
||
| 14 | while ($len < $maxlen && pow($base, $len) < $num) |
||
| 15 | $len++; |
||
| 16 | View Code Duplication | if ($len >= $maxlen) |
|
| 17 | throw new Exception($num." out of range (max ".pow($base, $maxlen - 1).")"); |
||
| 18 | $ceil = pow($base, $len); |
||
| 19 | $prime = $gp[$len]; |
||
| 20 | $dechash = ($num * $prime) % $ceil; |
||
| 21 | $hash = base_convert($dechash, 10, $base); |
||
| 22 | return str_pad($hash, $len, "0", STR_PAD_LEFT); |
||
| 23 | } |
||
| 24 | |||
| 40 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.