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.
Passed
Branch object-only (2b4c07)
by SignpostMarv
14:54
created

DaftObjectIdValuesHashLazyInt::DaftObjectIdHash()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 19
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
/**
3
* Base daft objects.
4
*
5
* @author SignpostMarv
6
*/
7
declare(strict_types=1);
8
9
namespace SignpostMarv\DaftObject;
10
11
/**
12
* @template T as DefinesOwnIdPropertiesInterface
13
*/
14
trait DaftObjectIdValuesHashLazyInt
15
{
16
    /**
17
    * @var array<string, array<string, string>>
18
    *
19
    * @psalm-var array<class-string<T>, array<string, string>>
20
    */
21
    private static $ids = [];
22
23
    /**
24
    * @psalm-param T $object
25
    *
26
    * @see DefinesOwnIdPropertiesInterface::DaftObjectIdHash()
27
    */
28
    public static function DaftObjectIdHash(DefinesOwnIdPropertiesInterface $object) : string
29
    {
30
        $id = [];
31
32
        /**
33
        * @var array<int, string>
34
        */
35
        $properties = $object::DaftObjectIdProperties();
36
37
        foreach ($properties as $prop) {
38
            /**
39
            * @var scalar|array|object|null
40
            */
41
            $val = $object->$prop;
42
43
            $id[] = static::VarExportNonScalars($val);
44
        }
45
46
        return static::DaftObjectIdValuesHash($id);
47
    }
48
49
    /**
50
    * @param (scalar|array|object|null)[] $id
51
    *
52
    * @see DefinesOwnIdPropertiesInterface::DaftObjectIdValuesHash()
53
    */
54
    public static function DaftObjectIdValuesHash(array $id) : string
55
    {
56
        $className = static::class;
57
58
        $objectIds = implode('::', array_map(static::class . '::VarExportNonScalars', $id));
59
60
        if ( ! isset(self::$ids[$className])) {
61
            self::$ids[$className] = [];
62
        }
63
64
        if ( ! isset(self::$ids[$className][$objectIds])) {
65
            self::$ids[$className][$objectIds] = static::VarExportNonScalars(count(
66
                self::$ids[$className]
67
            ));
68
        }
69
70
        return self::$ids[$className][$objectIds];
71
    }
72
73
    /**
74
    * @param mixed $maybe
75
    */
76
    private static function VarExportNonScalars($maybe) : string
77
    {
78
        if (is_string($maybe)) {
79
            return $maybe;
80
        }
81
82
        return
83
            is_scalar($maybe)
84
                ? (string) $maybe
85
                : var_export($maybe, true);
86
    }
87
}
88