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

Complexity

Total Complexity 14

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 14
lcom 0
cbo 0
dl 0
loc 70
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A hashAll() 0 4 1
A arrayHash() 0 11 1
C hash() 0 31 11
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