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.

Identity::hash()   C
last analyzed

Complexity

Conditions 11
Paths 11

Size

Total Lines 31
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 5.2653
c 0
b 0
f 0
cc 11
eloc 17
nc 11
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Pinq\Iterators\Common;
4
5
/**
6
 * Utility class for hashing the identity of any value as a string.
7
 *
8
 * @author Elliot Levin <[email protected]>
9
 */
10
final class Identity
11
{
12
    private function __construct()
13
    {
14
15
    }
16
17
    /**
18
     * Returns a string representing the supplied value's identity.
19
     *
20
     * @param mixed $value
21
     *
22
     * @return string
23
     */
24
    public static function hash($value)
25
    {
26
        $typeIdentifier = gettype($value)[0];
27
28
        switch ($typeIdentifier) {
29
30
            case 's': //string
31
32
                return 's' . (strlen($value) > 32 ? md5($value) : $value);
33
34
            case 'i': //integer
35
            case 'b': //boolean
36
            case 'd': //double
37
            case 'r': //resource
38
            case 'u': //unknown type
39
40
                return $typeIdentifier . $value;
41
42
            case 'N': //NULL
43
44
                return 'N';
45
46
            case 'o': //object
47
48
                return 'o' . spl_object_hash($value);
49
50
            case 'a': //array
51
52
                return self::arrayHash($value);
53
        }
54
    }
55
56
    /**
57
     * Returns an array of string representations of the supplied values
58
     *
59
     * @param mixed[] $values
60
     *
61
     * @return string[]
62
     */
63
    public static function hashAll(array $values)
64
    {
65
        return array_map([__CLASS__, 'hash'], $values);
66
    }
67
68
    private static function arrayHash(array $array)
69
    {
70
        array_walk_recursive(
71
                $array,
72
                function (&$value) {
73
                    $value = self::hash($value);
74
                }
75
        );
76
77
        return 'a' . md5(serialize($array));
78
    }
79
}
80