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.

RememberDaftObjectData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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