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 ( 04dd15...1f758d )
by SignpostMarv
06:31
created

DaftObjectMemoryRepository::ObjectHashId()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 1
crap 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A DaftObjectMemoryRepository::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
    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
        TypeParanoia::ThrowIfNotDaftObjectIdPropertiesType(
28 6
            $object,
29 6
            1,
30 6
            static::class,
31 6
            __FUNCTION__,
32 6
            $this->type
33
        );
34
35 4
        $hashId = $object::DaftObjectIdHash($object);
36
37 4
        $this->memory[$hashId] = $object;
38
39 4
        $this->RememberDaftObjectData($object);
40 4
    }
41
42
    /**
43
    * @param scalar|(scalar|array|object|null)[] $id
44
    */
45 4
    public function ForgetDaftObjectById($id) : void
46
    {
47 4
        $this->ForgetDaftObjectByHashId($this->type::DaftObjectIdValuesHash(
48 4
            TypeParanoia::ForceArgumentAsArray($id)
49
        ));
50 4
    }
51
52
    /**
53
    * @param scalar|(scalar|array|object|null)[] $id
54
    */
55 4
    public function RemoveDaftObjectById($id) : void
56
    {
57 4
        $this->RemoveDaftObjectByHashId($this->type::DaftObjectIdValuesHash(
58 4
            TypeParanoia::ForceArgumentAsArray($id)
59
        ));
60 4
    }
61
62
    /**
63
    * @param scalar|(scalar|array|object|null)[] $id
64
    */
65 4
    public function RecallDaftObject($id) : ? DaftObject
66
    {
67 4
        $hashId = $this->type::DaftObjectIdValuesHash(
68 4
            TypeParanoia::ForceArgumentAsArray($id)
69
        );
70
71 4
        if (false === isset($this->memory[$hashId])) {
72 4
            return $this->RecallDaftObjectFromData($id);
73
        }
74
75 4
        return $this->memory[$hashId];
76
    }
77
78 4
    public function RememberDaftObjectData(
79
        DefinesOwnIdPropertiesInterface $object,
80
        bool $assumeDoesNotExist = self::BOOL_DEFAULT_ASSUMEDOESNOTEXIST
81
    ) : void {
82 4
        $hashId = $object::DaftObjectIdHash($object);
83
84 4
        $this->data[$hashId] = [];
85
86 4
        foreach ($object::DaftObjectPublicGetters() as $property) {
87 4
            $this->data[$hashId][$property] = $object->__get($property);
88
        }
89 4
    }
90
91
    /**
92
    * Recalls the corresponding daft object instance from cached data.
93
    *
94
    * @param scalar|(scalar|array|object|null)[] $id
95
    */
96 8
    protected function RecallDaftObjectFromData($id) : ? DaftObject
97
    {
98 8
        $hashId = $this->type::DaftObjectIdValuesHash(
99 8
            TypeParanoia::ForceArgumentAsArray($id)
100
        );
101
102 8
        if (isset($this->data[$hashId])) {
103 4
            $type = $this->type;
104
105
            /**
106
            * @var DaftObject
107
            */
108 4
            $out = new $type($this->data[$hashId]);
109
110 4
            return $out;
111
        }
112
113 8
        return null;
114
    }
115
116 4
    private function ForgetDaftObjectByHashId(string $hashId) : void
117
    {
118 4
        if (true === isset($this->memory[$hashId])) {
119 4
            unset($this->memory[$hashId]);
120
        }
121 4
    }
122
123 4
    private function RemoveDaftObjectByHashId(string $hashId) : void
124
    {
125 4
        $this->ForgetDaftObjectByHashId($hashId);
126
127 4
        if (true === isset($this->data[$hashId])) {
128 4
            unset($this->data[$hashId]);
129
        }
130 4
    }
131
}
132