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 ( 57b168...a8fa9b )
by SignpostMarv
06:02
created

DaftObjectMemoryRepository::RememberDaftObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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
    * {@inheritdoc}
64
    *
65
    * @psalm-param T $object
66
    */
67 4
    public function RememberDaftObjectData(
68
        SuitableForRepositoryType $object,
69
        bool $assumeDoesNotExist = self::BOOL_DEFAULT_ASSUMEDOESNOTEXIST
70
    ) : void {
71 4
        $hashId = $object::DaftObjectIdHash($object);
72
73 4
        $this->data[$hashId] = [];
74
75 4
        foreach ($object::DaftObjectPublicGetters() as $property) {
76 4
            $this->data[$hashId][$property] = $object->__get($property);
77
        }
78 4
    }
79
80
    /**
81
    * Recalls the corresponding daft object instance from cached data.
82
    *
83
    * @param scalar|(scalar|array|object|null)[] $id
84
    *
85
    * @psalm-return T|null
86
    */
87 8
    protected function RecallDaftObjectFromData($id) : ? SuitableForRepositoryType
88
    {
89 8
        $hashId = $this->type::DaftObjectIdValuesHash(
90 8
            is_array($id) ? $id : [$id]
91
        );
92
93 8
        if (isset($this->data[$hashId])) {
94 4
            $type = $this->type;
95
96 4
            $out = new $type($this->data[$hashId]);
97
98 4
            return $out;
99
        }
100
101 8
        return null;
102
    }
103
104 4
    private function ForgetDaftObjectByHashId(string $hashId) : void
105
    {
106 4
        if (true === isset($this->memory[$hashId])) {
107 4
            unset($this->memory[$hashId]);
108
        }
109 4
    }
110
111 4
    private function RemoveDaftObjectByHashId(string $hashId) : void
112
    {
113 4
        $this->ForgetDaftObjectByHashId($hashId);
114
115 4
        if (true === isset($this->data[$hashId])) {
116 4
            unset($this->data[$hashId]);
117
        }
118 4
    }
119
}
120