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 ( 635be6...64d24b )
by SignpostMarv
04:41
created

DaftObjectMemoryRepository::ForgetDaftObjectById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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
class DaftObjectMemoryRepository extends AbstractDaftObjectRepository
12
{
13
    const BOOL_DEFAULT_ASSUMEDOESNOTEXIST = false;
14
15
    /**
16
    * @var DefinesOwnIdPropertiesInterface[]
17
    */
18
    protected $memory = [];
19
20
    /**
21
    * @var mixed[][]
22
    */
23
    protected $data = [];
24
25 6
    public function RememberDaftObject(DefinesOwnIdPropertiesInterface $object) : void
26
    {
27 6
        static::ThrowIfNotType($object, $this->type, 1, __FUNCTION__);
28
29 4
        $hashId = $object::DaftObjectIdHash($object);
30
31 4
        $this->memory[$hashId] = $object;
32
33 4
        $this->RememberDaftObjectData($object);
34 4
    }
35
36
    /**
37
    * @param mixed $id
38
    */
39 4
    public function ForgetDaftObjectById($id) : void
40
    {
41 4
        $this->ForgetDaftObjectByHashId($this->ObjectHashId($id));
42 4
    }
43
44
    /**
45
    * @param mixed $id
46
    */
47 4
    public function RemoveDaftObjectById($id) : void
48
    {
49 4
        $this->RemoveDaftObjectByHashId($this->ObjectHashId($id));
50 4
    }
51
52
    /**
53
    * @param mixed $id
54
    */
55 4
    public function RecallDaftObject($id) : ? DaftObject
56
    {
57 4
        $hashId = $this->ObjectHashId($id);
58
59 4
        if (false === isset($this->memory[$hashId])) {
60 4
            return $this->RecallDaftObjectFromData($id);
61
        }
62
63 4
        return $this->memory[$hashId];
64
    }
65
66 4
    public function RememberDaftObjectData(
67
        DefinesOwnIdPropertiesInterface $object,
68
        bool $assumeDoesNotExist = self::BOOL_DEFAULT_ASSUMEDOESNOTEXIST
69
    ) : void {
70 4
        $hashId = $object::DaftObjectIdHash($object);
71
72 4
        $this->data[$hashId] = [];
73
74 4
        foreach ($object::DaftObjectPublicGetters() as $property) {
75 4
            $getter = TypeUtilities::MethodNameFromProperty($property);
76
77
            /**
78
            * @var scalar|array|object|null
79
            */
80 4
            $val = $object->$getter();
81
82 4
            $this->data[$hashId][$property] = $val;
83
        }
84 4
    }
85
86
    /**
87
    * Recalls the corresponding daft object instance from cached data.
88
    *
89
    * @param mixed $id
90
    */
91 8
    protected function RecallDaftObjectFromData($id) : ? DaftObject
92
    {
93 8
        $hashId = $this->ObjectHashId($id);
94
95 8
        if (isset($this->data[$hashId])) {
96 4
            $type = $this->type;
97
98
            /**
99
            * @var DaftObject
100
            */
101 4
            $out = new $type($this->data[$hashId]);
102
103 4
            return $out;
104
        }
105
106 8
        return null;
107
    }
108
109
    /**
110
    * Converts an id to a unique-enough-for-now string.
111
    *
112
    * @param mixed $id
113
    */
114 8
    private function ObjectHashId($id) : string
115
    {
116 8
        return TypeParanoia::EnsureArgumentIsString(
117 8
            $this->type::DaftObjectIdValuesHash(
118 8
                TypeParanoia::ForceArgumentAsArray($id)
119
            )
120
        );
121
    }
122
123 4
    private function ForgetDaftObjectByHashId(string $hashId) : void
124
    {
125 4
        if (true === isset($this->memory[$hashId])) {
126 4
            unset($this->memory[$hashId]);
127
        }
128 4
    }
129
130 4
    private function RemoveDaftObjectByHashId(string $hashId) : void
131
    {
132 4
        $this->ForgetDaftObjectByHashId($hashId);
133
134 4
        if (true === isset($this->data[$hashId])) {
135 4
            unset($this->data[$hashId]);
136
        }
137 4
    }
138
}
139