GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Nip_Hash::uhash()   B
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 15
Code Lines 13

Duplication

Lines 2
Ratio 13.33 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 8
nop 3
dl 2
loc 15
ccs 0
cts 13
cp 0
crap 30
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
class Nip_Hash
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
	protected static $golden_primes = array(
7
		36 => array(1, 23, 809, 28837, 1038073, 37370257, 1345328833)
8
	);
9
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)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
26
}
27