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 ( f06180...d17a44 )
by SignpostMarv
06:19
created

DaftObjectRepositoryByDaftObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 10
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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 DefinesOwnIdPropertiesInterface&DaftObjectCreatedByArray
13
*
14
* @template-implements DaftObjectRepository<T>
15
*/
16
abstract class AbstractDaftObjectRepository implements DaftObjectRepository
17
{
18
    /**
19
    * @var DefinesOwnIdPropertiesInterface[]
20
    */
21
    protected $memory = [];
22
23
    /**
24
    * @var array<string, array<string, mixed>>
25
    */
26
    protected $data = [];
27
28
    /**
29
    * @var string
30
    *
31
    * @psalm-var class-string<T>
32
    */
33
    protected $type;
34
35
    /**
36
    * @var mixed[]|null
37
    */
38
    protected $args;
39
40
    /**
41
    * @param mixed ...$args
42
    *
43
    * @psalm-param class-string<T> $type
44
    */
45 14
    protected function __construct(string $type, ...$args)
46
    {
47 14
        $this->type = $type;
48 14
        $this->args = $args;
49 14
        unset($this->args);
50 14
    }
51
52
    /**
53
    * {@inheritdoc}
54
    */
55 6
    public function ForgetDaftObject(DefinesOwnIdPropertiesInterface $object) : void
56
    {
57 6
        TypeParanoia::ThrowIfNotDaftObjectIdPropertiesType(
58 6
            $object,
59 6
            1,
60 6
            static::class,
61 6
            __FUNCTION__,
62 6
            $this->type
63
        );
64
65
        /**
66
        * @var (scalar|array|object|null)[]
67
        */
68 4
        $id = [];
69
70 4
        foreach ($object::DaftObjectIdProperties() as $prop) {
71
            /**
72
            * @var scalar|array|object|null
73
            */
74 4
            $id_val = $object->__get($prop);
75
76 4
            $id[] = $id_val;
77
        }
78
79 4
        $this->ForgetDaftObjectById($id);
80 4
    }
81
82
    /**
83
    * {@inheritdoc}
84
    */
85 6
    public function RemoveDaftObject(DefinesOwnIdPropertiesInterface $object) : void
86
    {
87 6
        TypeParanoia::ThrowIfNotDaftObjectIdPropertiesType(
88 6
            $object,
89 6
            1,
90 6
            static::class,
91 6
            __FUNCTION__,
92 6
            $this->type
93
        );
94
95
        /**
96
        * @var (scalar|array|object|null)[]
97
        */
98 4
        $id = [];
99
100
        /**
101
        * @var array<int, string>
102
        */
103 4
        $properties = $object::DaftObjectIdProperties();
104
105 4
        foreach ($properties as $prop) {
106
            /**
107
            * @var scalar|array|object|null
108
            */
109 4
            $id_val = $object->__get($prop);
110
111 4
            $id[] = $id_val;
112
        }
113
114 4
        $this->RemoveDaftObjectById($id);
115 4
    }
116
117
    /**
118
    * {@inheritdoc}
119
    *
120
    * @psalm-param class-string<T> $type
121
    *
122
    * @psalm-return AbstractDaftObjectRepository<T>
123
    */
124 18
    public static function DaftObjectRepositoryByType(
125
        string $type,
126
        ...$args
127
    ) : DaftObjectRepository {
128 18
        TypeParanoia::ThrowIfNotType(
129 18
            $type,
130 18
            1,
131 18
            static::class,
132 18
            __FUNCTION__,
133 18
            DaftObjectCreatedByArray::class,
134 18
            DefinesOwnIdPropertiesInterface::class
135
        );
136
137 12
        return new static($type, ...$args);
138
    }
139
140
    /**
141
    * {@inheritdoc}
142
    *
143
    * @psalm-param T $object
144
    *
145
    * @psalm-return AbstractDaftObjectRepository<T>
146
    */
147 10
    public static function DaftObjectRepositoryByDaftObject(
148
        DefinesOwnIdPropertiesInterface $object,
149
        ...$args
150
    ) : DaftObjectRepository {
151
        /**
152
        * @psalm-var class-string<T>
153
        */
154 10
        $className = get_class($object);
155
156 10
        return static::DaftObjectRepositoryByType($className, ...$args);
157
    }
158
}
159