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.
Completed
Push — master ( ac587f...53bcfa )
by SignpostMarv
07:07
created

DaftObjectMemoryRepository   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 117
ccs 0
cts 59
cp 0
rs 10
c 0
b 0
f 0
wmc 15

9 Methods

Rating   Name   Duplication   Size   Complexity  
A ForgetDaftObjectById() 0 3 1
A RememberDaftObjectData() 0 9 2
A RecallDaftObject() 0 9 2
A RemoveDaftObjectById() 0 3 1
A RemoveDaftObjectByHashId() 0 6 2
A RememberDaftObject() 0 9 1
A ObjectHashId() 0 10 2
A RecallDaftObjectFromData() 0 15 2
A ForgetDaftObjectByHashId() 0 4 2
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
    /**
14
    * @var DefinesOwnIdPropertiesInterface[]
15
    */
16
    protected $memory = [];
17
18
    /**
19
    * mixed[][].
20
    */
21
    protected $data = [];
22
23
    public function RememberDaftObject(DefinesOwnIdPropertiesInterface $object) : void
24
    {
25
        static::ThrowIfNotType($object, $this->type, 1, __FUNCTION__);
26
27
        $hashId = $object::DaftObjectIdHash($object);
28
29
        $this->memory[$hashId] = $object;
30
31
        $this->RememberDaftObjectData($object);
32
    }
33
34
    /**
35
    * @param mixed $id
36
    */
37
    public function ForgetDaftObjectById($id) : void
38
    {
39
        $this->ForgetDaftObjectByHashId($this->ObjectHashId($id));
40
    }
41
42
    /**
43
    * @param mixed $id
44
    */
45
    public function RemoveDaftObjectById($id) : void
46
    {
47
        $this->RemoveDaftObjectByHashId($this->ObjectHashId($id));
48
    }
49
50
    /**
51
    * @param mixed $id
52
    */
53
    public function RecallDaftObject($id) : ? DaftObject
54
    {
55
        $hashId = $this->ObjectHashId($id);
56
57
        if (false === isset($this->memory[$hashId])) {
58
            return $this->RecallDaftObjectFromData($id);
59
        }
60
61
        return $this->memory[$hashId];
62
    }
63
64
    protected function RememberDaftObjectData(DefinesOwnIdPropertiesInterface $object) : void
65
    {
66
        $hashId = $object::DaftObjectIdHash($object);
67
68
        $this->data[$hashId] = [];
69
70
        foreach ($object::DaftObjectPublicGetters() as $property) {
71
            $getter = 'Get' . ucfirst($property);
72
            $this->data[$hashId][$property] = $object->$getter();
73
        }
74
    }
75
76
    /**
77
    * Recalls the corresponding daft object instance from cached data.
78
    *
79
    * @param mixed $id
80
    */
81
    protected function RecallDaftObjectFromData($id) : ? DaftObject
82
    {
83
        $hashId = $this->ObjectHashId($id);
84
        if (true === isset($this->data[$hashId])) {
85
            $type = $this->type;
86
87
            /**
88
            * @var DaftObject $out
89
            */
90
            $out = new $type($this->data[$hashId]);
91
92
            return $out;
93
        }
94
95
        return null;
96
    }
97
98
    /**
99
    * Converts an id to a unique-enough-for-now string.
100
    *
101
    * @param mixed $id
102
    */
103
    private function ObjectHashId($id) : string
104
    {
105
        $id = is_array($id) ? $id : [$id];
106
107
        /**
108
        * @var DefinesOwnIdPropertiesInterface $type
109
        */
110
        $type = $this->type;
111
112
        return $type::DaftObjectIdValuesHash($id);
113
    }
114
115
    private function ForgetDaftObjectByHashId(string $hashId) : void
116
    {
117
        if (true === isset($this->memory[$hashId])) {
118
            unset($this->memory[$hashId]);
119
        }
120
    }
121
122
    private function RemoveDaftObjectByHashId(string $hashId) : void
123
    {
124
        $this->ForgetDaftObjectByHashId($hashId);
125
126
        if (true === isset($this->data[$hashId])) {
127
            unset($this->data[$hashId]);
128
        }
129
    }
130
}
131