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_Helper_Hash::uhash()   B
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 18
Code Lines 15

Duplication

Lines 2
Ratio 11.11 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 15
nc 8
nop 3
dl 2
loc 18
ccs 0
cts 14
cp 0
crap 30
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
class Nip_Helper_Hash extends Nip\Helpers\AbstractHelper
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
    function uhash($num, $len = 10, $base = 36)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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)
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...
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
25
	/**
26
	 * Singleton
27
	 *
28
	 * @return Nip_Helper_Hash
29
	 */
30
	static public function instance()
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
31
	{
32
		static $instance;
33
		if (!($instance instanceof self)) {
34
			$instance = new self();
35
		}
36
		return $instance;
37
	}
38
39
40
}