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   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 5.26 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 2
loc 38
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
B uhash() 2 18 5
A instance() 0 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}