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 ( 988e43...1acf5e )
by SignpostMarv
06:14
created

RecallDaftObjectOrThrow()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
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
    * {@inheritdoc}
64
    *
65
    * @psalm-return T
66
    */
67 4
    final public function RecallDaftObjectOrThrow($id) : SuitableForRepositoryType
68
    {
69 4
        $out = static::RecallDaftObject($id);
0 ignored issues
show
Bug Best Practice introduced by
The method SignpostMarv\DaftObject\...ory::RecallDaftObject() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
        /** @scrutinizer ignore-call */ 
70
        $out = static::RecallDaftObject($id);
Loading history...
70
71 4
        if (is_null($out)) {
72 4
            throw new DaftObjectNotRecalledException(
73
                'Argument 1 passed to ' .
74
                DaftObjectRepository::class .
75
                '::RecallDaftObjectOrThrow() did not resolve to an instance of ' .
76
                SuitableForRepositoryType::class .
77
                ' from ' .
78 4
                static::class .
79 4
                '::RecallDaftObject()'
80
            );
81
        }
82
83 4
        return $out;
84
    }
85
86
    /**
87
    * {@inheritdoc}
88
    *
89
    * @psalm-param T $object
90
    */
91 4
    public function RememberDaftObjectData(
92
        SuitableForRepositoryType $object,
93
        bool $assumeDoesNotExist = self::BOOL_DEFAULT_ASSUMEDOESNOTEXIST
94
    ) : void {
95 4
        $hashId = $object::DaftObjectIdHash($object);
96
97 4
        $this->data[$hashId] = [];
98
99 4
        foreach ($object::DaftObjectPublicGetters() as $property) {
100 4
            $this->data[$hashId][$property] = $object->__get($property);
101
        }
102 4
    }
103
104
    /**
105
    * Recalls the corresponding daft object instance from cached data.
106
    *
107
    * @param scalar|(scalar|array|object|null)[] $id
108
    *
109
    * @psalm-return T|null
110
    */
111 8
    protected function RecallDaftObjectFromData($id) : ? SuitableForRepositoryType
112
    {
113 8
        $hashId = $this->type::DaftObjectIdValuesHash(
114 8
            is_array($id) ? $id : [$id]
115
        );
116
117 8
        if (isset($this->data[$hashId])) {
118 4
            $type = $this->type;
119
120 4
            $out = new $type($this->data[$hashId]);
121
122 4
            return $out;
123
        }
124
125 8
        return null;
126
    }
127
128 4
    private function ForgetDaftObjectByHashId(string $hashId) : void
129
    {
130 4
        if (true === isset($this->memory[$hashId])) {
131 4
            unset($this->memory[$hashId]);
132
        }
133 4
    }
134
135 4
    private function RemoveDaftObjectByHashId(string $hashId) : void
136
    {
137 4
        $this->ForgetDaftObjectByHashId($hashId);
138
139 4
        if (true === isset($this->data[$hashId])) {
140 4
            unset($this->data[$hashId]);
141
        }
142 4
    }
143
}
144