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 ( a67098...e6e3d2 )
by SignpostMarv
01:42
created

DaftObjectMemoryRepository::ObjectHashId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 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
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(
24
        DefinesOwnIdPropertiesInterface $object
25
    ) : void {
26
        if (is_a($object, $this->type, true) === false) {
27
            throw new DaftObjectRepositoryTypeException(
28
                'Argument 1 passed to ' .
0 ignored issues
show
Unused Code introduced by
The call to DaftObjectRepositoryTypeException::__construct() has too many arguments starting with 'Argument 1 passed to ' ...ss($object) . ' given.'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
29
                static::class .
30
                '::' .
31
                __FUNCTION__ .
32
                '() must be an instance of ' .
33
                $this->type .
34
                ', ' .
35
                get_class($object) .
36
                ' given.'
37
            );
38
        }
39
40
        $hashId = $object::DaftObjectIdHash($object);
41
42
        $this->memory[$hashId] = $object;
43
44
        if (isset($this->data[$hashId]) === false) {
45
            $this->data[$hashId] = [];
46
        }
47
48
        foreach ($object::DaftObjectProperties() as $property) {
49
            $getter = 'Get' . ucfirst($property);
50
51
            if (
52
                method_exists($object, $getter) === true &&
53
                isset($object->$property)
54
            ) {
55
                $this->data[$hashId][$property] = $object->$getter();
56
            }
57
        }
58
    }
59
60
    public function ForgetDaftObjectById($id) : void
61
    {
62
        $this->ForgetDaftObjectByHashId($this->ObjectHashId($id));
63
    }
64
65
    public function RemoveDaftObjectById($id) : void
66
    {
67
        $this->RemoveDaftObjectByHashId($this->ObjectHashId($id));
68
    }
69
70
    public function RecallDaftObject($id) : ? DaftObject
71
    {
72
        $hashId = $this->ObjectHashId($id);
73
74
        if (isset($this->memory[$hashId]) === false) {
75
            if (isset($this->data[$hashId]) === true) {
76
                $type = $this->type;
77
78
                return new $type($this->data[$hashId]);
79
            }
80
81
            return null;
82
        }
83
84
        return $this->memory[$hashId];
85
    }
86
87
    private function ObjectHashId($id) : string
88
    {
89
        $id = is_array($id) ? $id : [$id];
90
91
        $type = $this->type;
92
93
        return $type::DaftObjectIdValuesHash($id);
94
    }
95
96
    private function ForgetDaftObjectByHashId(string $hashId) : void
97
    {
98
        if (isset($this->memory[$hashId]) === true) {
99
            unset($this->memory[$hashId]);
100
        }
101
    }
102
103
    private function RemoveDaftObjectByHashId(string $hashId) : void
104
    {
105
        $this->ForgetDaftObjectByHashId($hashId);
106
107
        if (isset($this->data[$hashId]) === true) {
108
            unset($this->data[$hashId]);
109
        }
110
    }
111
}
112