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
Push — master ( f00e57...f8ae9a )
by SignpostMarv
03:36
created

DaftObjectIdValuesHash()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 28
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 4
nop 1
dl 0
loc 28
ccs 14
cts 14
cp 1
crap 3
rs 9.8333
c 0
b 0
f 0
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 4
    public static function DaftObjectIdHash(DefinesOwnIdPropertiesInterface $object) : string
29
    {
30 4
        return static::DaftObjectIdValuesHash(array_map(
31
            function (string $prop) use ($object) : string {
32
                /**
33
                * @var scalar|array|object|null
34
                */
35 4
                $val = $object->__get($prop);
36
37 4
                return static::VarExportNonScalars($val);
38 4
            },
39 4
            $object::DaftObjectIdProperties()
40
        ));
41
    }
42
43
    /**
44
    * @param (scalar|array|object|null)[] $id
45
    *
46
    * @see DefinesOwnIdPropertiesInterface::DaftObjectIdValuesHash()
47
    */
48 4
    public static function DaftObjectIdValuesHash(array $id) : string
49
    {
50 4
        $className = static::class;
51
52 4
        $objectIds = implode(
53 4
            '::',
54 3
            array_map(
55
                /**
56
                * @param scalar|array|object|null $val
57
                */
58
                function ($val) : string {
59 4
                    return static::VarExportNonScalars($val);
60 4
                },
61 2
                $id
62
            )
63
        );
64
65 4
        if ( ! isset(self::$ids[$className])) {
66 4
            self::$ids[$className] = [];
67
        }
68
69 4
        if ( ! isset(self::$ids[$className][$objectIds])) {
70 4
            self::$ids[$className][$objectIds] = static::VarExportNonScalars(count(
71 4
                self::$ids[$className]
72
            ));
73
        }
74
75 4
        return self::$ids[$className][$objectIds];
76
    }
77
78
    /**
79
    * @param scalar|array|object|null $maybe
80
    */
81 4
    private static function VarExportNonScalars($maybe) : string
82
    {
83 4
        if (is_string($maybe)) {
84 4
            return $maybe;
85
        }
86
87
        return
88 4
            is_scalar($maybe)
89 4
                ? (string) $maybe
90 4
                : var_export($maybe, true);
91
    }
92
}
93