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.
Test Failed
Push — php7.3 ( a4fbeb...9ddd99 )
by SignpostMarv
06:05
created

DaftObjectPropertiesWithMultiTypedArraysOfUniqueValues()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
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
* Base daft object.
13
*/
14
abstract class AbstractDaftObject implements DaftObject
15
{
16
    /**
17
    * List of properties that can be defined on an implementation.
18
    *
19
    * @var array<int, string>
20
    */
21
    const PROPERTIES = [];
22
23
    /**
24
    * List of nullable properties that can be defined on an implementation.
25
    *
26
    * @var array<int, string>
27
    */
28
    const NULLABLE_PROPERTIES = [];
29
30
    /**
31
    * List of exportable properties that can be defined on an implementation.
32
    *
33
    * @var array<int, string>
34
    */
35
    const EXPORTABLE_PROPERTIES = [];
36
37
    /**
38
    * import/export definition for DaftJson.
39
    *
40
    * @var array<int, string>
41
    */
42
    const JSON_PROPERTIES = [];
43
44
    /**
45
    * List of sortable properties for DaftSortableObject.
46
    *
47
    * @var array<int, string>
48
    */
49
    const SORTABLE_PROPERTIES = [];
50
51
    /**
52
    * @var array<string, array<int, string>>
53
    */
54
    const CHANGE_OTHER_PROPERTIES = [];
55
56
    /**
57
    * @var array<string, array<int, string>>
58
    */
59
    const PROPERTIES_WITH_MULTI_TYPED_ARRAYS = [];
60
61
    /**
62 260
    * Does some sanity checking.
63
    *
64 260
    * @see DefinesOwnIdPropertiesInterface
65 260
    * @see TypeUtilities::CheckTypeDefinesOwnIdProperties()
66 260
    */
67
    public function __construct()
68 258
    {
69
        TypeUtilities::CheckTypeDefinesOwnIdProperties(
70
            static::class,
71
            ($this instanceof DefinesOwnIdPropertiesInterface)
72
        );
73 42
    }
74
75 42
    /**
76
    * @return mixed
77
    */
78
    public function __get(string $property)
79
    {
80
        return $this->DoGetSet($property, false);
81 85
    }
82
83 85
    /**
84 81
    * @param mixed $v
85
    */
86
    public function __set(string $property, $v) : void
87
    {
88
        $this->DoGetSet($property, true, $v);
89 23
    }
90
91 23
    /**
92 21
    * @see static::NudgePropertyValue()
93
    */
94
    public function __unset(string $property) : void
95
    {
96
        $this->NudgePropertyValue($property, null);
97 36
    }
98
99 36
    /**
100 36
    * @return array<string, mixed>
101
    */
102
    public function __debugInfo() : array
103
    {
104
        $getters = static::DaftObjectPublicGetters();
105 35
        $exportables = static::DaftObjectExportableProperties();
106 36
        /**
107
        * @var array<int, string>
108
        */
109
        $properties = array_filter($exportables, function (string $prop) use ($getters) : bool {
110
            return $this->__isset($prop) && TypeParanoia::MaybeInArray($prop, $getters);
111 36
        });
112
113
        /**
114
        * @var array<string, mixed>
115
        */
116 29
        $out = array_combine($properties, array_map(
117
            /**
118 29
            * @return mixed
119 36
            */
120
            function (string $prop) {
121
                $expectedMethod = TypeUtilities::MethodNameFromProperty($prop);
122
123 36
                return $this->$expectedMethod();
124
            },
125
            $properties
126 2
        ));
127
128 2
        return $out;
129 1
    }
130 1
131 1
    public function CompareToDaftSortableObject(DaftSortableObject $otherObject) : int
132
    {
133
        if ( ! is_a(static::class, DaftSortableObject::class, true)) {
134
            throw new ClassDoesNotImplementClassException(
135
                static::class,
136
                DaftSortableObject::class
137
            );
138 1
        }
139 1
140 1
        foreach (static::DaftSortableObjectProperties() as $property) {
141
            $method = TypeUtilities::MethodNameFromProperty($property);
142 1
            $sort = $this->$method() <=> $otherObject->$method();
143 1
144
            if (0 !== $sort) {
145
                return $sort;
146
            }
147 1
        }
148
149
        return 0;
150
    }
151
152
    /**
153
    * List of properties that can be defined on an implementation.
154
    *
155 183
    * @return array<int, string>
156
    */
157
    public static function DaftObjectProperties() : array
158
    {
159
        /**
160 183
        * @var array<int, string>
161
        */
162 183
        $out = static::PROPERTIES;
163
164
        return $out;
165 55
    }
166
167
    public static function DaftObjectNullableProperties() : array
168
    {
169
        /**
170 55
        * @var array<int, string>
171
        */
172 55
        $out = static::NULLABLE_PROPERTIES;
173
174
        return $out;
175 73
    }
176
177
    public static function DaftObjectExportableProperties() : array
178
    {
179
        /**
180 73
        * @var array<int, string>
181
        */
182 73
        $out = static::EXPORTABLE_PROPERTIES;
183
184
        return $out;
185 55
    }
186
187 55
    final public static function DaftObjectPublicGetters() : array
188
    {
189
        return TypeUtilities::DaftObjectPublicGetters(static::class);
190 1
    }
191
192 1
    final public static function DaftObjectPublicOrProtectedGetters() : array
193
    {
194
        return TypeUtilities::DaftObjectPublicOrProtectedGetters(static::class);
195 85
    }
196
197 85
    final public static function DaftObjectPublicSetters() : array
198
    {
199
        return TypeUtilities::DaftObjectPublicSetters(static::class);
200 39
    }
201
202 39
    public static function DaftObjectJsonProperties() : array
203
    {
204
        JsonTypeUtilities::ThrowIfNotDaftJson(static::class);
205
206
        /**
207 18
        * @var array<int|string, string>
208
        */
209 18
        $out = static::JSON_PROPERTIES;
210
211
        return $out;
212 18
    }
213
214 18
    final public static function DaftObjectJsonPropertyNames() : array
215
    {
216
        $out = [];
217
218
        /**
219 18
        * @var array<int|string, string>
220
        */
221 18
        $jsonProperties = static::DaftObjectJsonProperties();
222 18
223 12
        foreach ($jsonProperties as $k => $prop) {
224
            if (is_string($k)) {
225
                $prop = $k;
226 18
            }
227
228
            $out[] = $prop;
229 18
        }
230
231
        return $out;
232 19
    }
233
234 19
    /**
235 17
    * @return array<int, string>
236 17
    */
237 17
    public static function DaftSortableObjectProperties() : array
238
    {
239
        if ( ! is_a(static::class, DaftSortableObject::class, true)) {
240
            throw new ClassDoesNotImplementClassException(
241
                static::class,
242
                DaftSortableObject::class
243
            );
244 2
        }
245
246 2
        /**
247
        * @var array<int, string>
248
        */
249
        $out = static::SORTABLE_PROPERTIES;
250
251
        return $out;
252 37
    }
253
254
    /**
255
    * @return array<string, array<int, string>>
256
    */
257 37
    public static function DaftObjectPropertiesChangeOtherProperties() : array
258
    {
259 37
        /**
260
        * @var array<string, array<int, string>>
261
        */
262
        $out = static::CHANGE_OTHER_PROPERTIES;
263
264
        return $out;
265
    }
266
267
    /**
268
    * @return array<string, array<int, string>>
269
    */
270
    public static function DaftObjectPropertiesWithMultiTypedArraysOfUniqueValues() : array
271
    {
272
        if (
273
            ! is_a(
274 109
                static::class,
275
                DaftObjectHasPropertiesWithMultiTypedArraysOfUniqueValues::class,
276 109
                true
277 5
            )
278 3
        ) {
279 2
            throw new ClassDoesNotImplementClassException(
280 1
                static::class,
281
                DaftObjectHasPropertiesWithMultiTypedArraysOfUniqueValues::class
282
            );
283 1
        }
284
285 104
        /**
286
        * @var array<string, array<int, string>>
287
        */
288
        $out = static::PROPERTIES_WITH_MULTI_TYPED_ARRAYS;
289
290
        return $out;
291
    }
292 109
293
    /**
294 109
    * Nudge the state of a given property, marking it as dirty.
295
    *
296 109
    * @param string $property property being nudged
297
    * @param scalar|array|object|null $value value to nudge property with
298 104
    *
299
    * @throws UndefinedPropertyException if $property is not in static::DaftObjectProperties()
300
    * @throws PropertyNotNullableException if $property is not in static::DaftObjectNullableProperties()
301
    * @throws PropertyNotRewriteableException if class is write-once read-many and $property was already changed
302
    */
303
    abstract protected function NudgePropertyValue(string $property, $value) : void;
304
305
    protected function MaybeThrowOnDoGetSet(string $property, bool $setter, array $props) : void
306
    {
307
        if ( ! TypeParanoia::MaybeInArray($property, $props)) {
308
            if ( ! TypeParanoia::MaybeInArray($property, static::DaftObjectProperties())) {
309
                throw new UndefinedPropertyException(static::class, $property);
310
            } elseif ($setter) {
311
                throw new NotPublicSetterPropertyException(static::class, $property);
312
            }
313
314
            throw new NotPublicGetterPropertyException(static::class, $property);
315
        }
316
    }
317
318
    /**
319
    * @param mixed $v
320
    *
321
    * @return mixed
322
    */
323
    protected function DoGetSet(string $property, bool $setter, $v = null)
324
    {
325
        $props = $setter ? static::DaftObjectPublicSetters() : static::DaftObjectPublicGetters();
326
327
        $this->MaybeThrowOnDoGetSet($property, $setter, $props);
328
329
        return $this->{TypeUtilities::MethodNameFromProperty($property, $setter)}($v);
330
    }
331
}
332