| Conditions | 5 |
| Paths | 8 |
| Total Lines | 15 |
| Code Lines | 13 |
| Lines | 2 |
| Ratio | 13.33 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | public static function uhash($num, $len = 5, $base = 36) |
||
| 11 | { |
||
| 12 | $gp = self::$golden_primes[$base]; |
||
| 13 | $maxlen = count($gp); |
||
| 14 | $len = $len > ($maxlen - 1) ? ($maxlen - 1) : $len; |
||
| 15 | while ($len < $maxlen && pow($base, $len) < $num) |
||
| 16 | $len++; |
||
| 17 | View Code Duplication | if ($len >= $maxlen) |
|
| 18 | throw new Exception($num . " out of range (max " . pow($base, $maxlen - 1) . ")"); |
||
| 19 | $ceil = pow($base, $len); |
||
| 20 | $prime = $gp[$len]; |
||
| 21 | $dechash = ($num * $prime) % $ceil; |
||
| 22 | $hash = base_convert($dechash, 10, $base); |
||
| 23 | return str_pad($hash, $len, "0", STR_PAD_LEFT); |
||
| 24 | } |
||
| 25 | |||
| 27 |
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.