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.

DaftObjectIdValuesHashLazyInt   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 77
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A DaftObjectIdHash() 0 12 1
A VarExportNonScalars() 0 10 3
A DaftObjectIdValuesHash() 0 28 3
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