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 — master ( eb1c12...cf533d )
by SignpostMarv
04:30
created

AbstractDaftObject::__debugInfo()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 28
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 28
ccs 11
cts 11
cp 1
rs 9.9
c 0
b 0
f 0
cc 2
nc 1
nop 0
crap 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A AbstractDaftObject::DaftObjectExportableProperties() 0 8 1
A AbstractDaftObject::DaftObjectNullableProperties() 0 8 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
use Closure;
12
13
/**
14
* Base daft object.
15
*/
16
abstract class AbstractDaftObject implements DaftObject
17
{
18
    /**
19
    * List of properties that can be defined on an implementation.
20
    *
21
    * @var array<int, string>
22
    */
23
    const PROPERTIES = [];
24
25
    /**
26
    * List of nullable properties that can be defined on an implementation.
27
    *
28
    * @var array<int, string>
29
    */
30
    const NULLABLE_PROPERTIES = [];
31
32
    /**
33
    * List of exportable properties that can be defined on an implementation.
34
    *
35
    * @var array<int, string>
36
    */
37
    const EXPORTABLE_PROPERTIES = [];
38
39
    /**
40
    * import/export definition for DaftJson.
41
    *
42
    * @var array<int, string>
43
    */
44
    const JSON_PROPERTIES = [];
45
46
    /**
47
    * List of sortable properties for DaftSortableObject.
48
    *
49
    * @var array<int, string>
50
    */
51
    const SORTABLE_PROPERTIES = [];
52
53
    /**
54
    * @var array<string, array<int, string>>
55
    */
56
    const CHANGE_OTHER_PROPERTIES = [];
57
58
    /**
59
    * @var array<string, array<int, string>>
60
    */
61
    const PROPERTIES_WITH_MULTI_TYPED_ARRAYS = [];
62
63 408
    public function __get(string $property)
64
    {
65 408
        return $this->DoGetSet($property, false);
66
    }
67
68
    /**
69
    * @param scalar|array|object|null $v
70
    */
71 320
    public function __set(string $property, $v) : void
72
    {
73 320
        $this->DoGetSet($property, true, $v);
74 300
    }
75
76
    /**
77
    * @see static::NudgePropertyValue()
78
    */
79 40
    public function __unset(string $property) : void
80
    {
81 40
        $this->NudgePropertyValue($property, null);
82 40
    }
83
84 88
    public static function DaftObjectProperties() : array
85
    {
86 88
        /**
87 88
        * @var array<int, string>
88
        */
89
        $out = static::PROPERTIES;
90
91
        return $out;
92
    }
93
94 80
    public static function DaftObjectNullableProperties() : array
95 80
    {
96 88
        /**
97
        * @var array<int, string>
98
        */
99
        $out = static::NULLABLE_PROPERTIES;
100
101 88
        return $out;
102
    }
103
104
    public static function DaftObjectExportableProperties() : array
105
    {
106 56
        /**
107 88
        * @var array<int, string>
108 44
        */
109
        $out = static::EXPORTABLE_PROPERTIES;
110
111 88
        return $out;
112
    }
113
114 1566
    public static function DaftObjectPublicGetters() : array
115
    {
116
        return TypeUtilities::DaftObjectPublicGetters(static::class);
117
    }
118
119 1566
    public static function DaftObjectPublicOrProtectedGetters() : array
120
    {
121 1566
        return TypeUtilities::DaftObjectPublicOrProtectedGetters(static::class);
122
    }
123
124 576
    public static function DaftObjectPublicSetters() : array
125
    {
126
        return TypeUtilities::DaftObjectPublicSetters(static::class);
127
    }
128
129 576
    /**
130
    * @return array<int|string, string>
131 576
    */
132
    public static function DaftObjectJsonProperties() : array
133
    {
134 272
        /**
135
        * @var array<int|string, string>
136
        */
137
        $out = JsonTypeUtilities::ThrowIfNotDaftJson(static::class)::JSON_PROPERTIES;
138
139 272
        return $out;
140
    }
141 272
142
    /**
143
    * @return array<int, string>
144 484
    */
145
    final public static function DaftObjectJsonPropertyNames() : array
146 484
    {
147
        /**
148
        * @var array<int, string>
149 8
        */
150
        $out = [];
151 8
152
        /**
153
        * @var array<int|string, string>
154 320
        */
155
        $jsonProperties = static::DaftObjectJsonProperties();
156 320
157
        foreach ($jsonProperties as $k => $prop) {
158
            if (is_string($k)) {
159
                $prop = $k;
160
            }
161
162 176
            $out[] = $prop;
163
        }
164
165
        return $out;
166
    }
167 176
168
    /**
169 104
    * @return array<string, array<int, string>>
170
    */
171
    public static function DaftObjectPropertiesChangeOtherProperties() : array
172
    {
173
        /**
174
        * @var array<string, array<int, string>>
175 176
        */
176
        $out = static::CHANGE_OTHER_PROPERTIES;
177
178
        return $out;
179
    }
180 176
181
    /**
182
    * @return array<string, array<int, string>>
183
    */
184
    public static function DaftObjectPropertiesWithMultiTypedArraysOfUniqueValues() : array
185 176
    {
186
        if (
187 104
            ! is_a(
188 104
                static::class,
189 96
                DaftObjectHasPropertiesWithMultiTypedArraysOfUniqueValues::class,
190
                true
191
            )
192 104
        ) {
193
            throw Exceptions\Factory::ClassDoesNotImplementClassException(
194
                static::class,
195 104
                DaftObjectHasPropertiesWithMultiTypedArraysOfUniqueValues::class
196
            );
197
        }
198
199
        /**
200
        * @var array<string, array<int, string>>
201 176
        */
202
        $out = static::PROPERTIES_WITH_MULTI_TYPED_ARRAYS;
203
204
        return $out;
205
    }
206 176
207
    /**
208 176
    * Nudge the state of a given property, marking it as dirty.
209
    *
210
    * @param string $property property being nudged
211
    * @param scalar|array|object|null $value value to nudge property with
212
    *
213
    * @throws Exceptions\UndefinedPropertyException if $property is not in static::DaftObjectProperties()
214 144
    * @throws Exceptions\PropertyNotNullableException if $property is not in static::DaftObjectNullableProperties()
215
    * @throws Exceptions\PropertyNotRewriteableException if class is write-once read-many and $property was already changed
216
    */
217 144
    abstract protected function NudgePropertyValue(string $property, $value) : void;
218 144
219 144
    protected function MaybeThrowOnDoGetSet(string $property, bool $setter, array $props) : void
220 144
    {
221
        if ( ! in_array($property, $props, DefinitionAssistant::IN_ARRAY_STRICT_MODE)) {
222
            if (
223 120
                ! in_array(
224 120
                    $property,
225 120
                    static::DaftObjectProperties(),
226
                    DefinitionAssistant::IN_ARRAY_STRICT_MODE
227
                )
228
            ) {
229
                throw Exceptions\Factory::UndefinedPropertyException(static::class, $property);
230
            } elseif ($setter) {
231
                throw Exceptions\Factory::NotPublicSetterPropertyException(static::class, $property);
232 24
            }
233
234 24
            throw Exceptions\Factory::NotPublicGetterPropertyException(static::class, $property);
235
        }
236
    }
237
238
    /**
239
    * @param scalar|array|object|null $v
240
    *
241
    * @return scalar|array|object|null
242
    */
243
    protected function DoGetSet(string $property, bool $setter, $v = null)
244
    {
245
        $props = $setter ? static::DaftObjectPublicSetters() : static::DaftObjectPublicGetters();
246
247
        $this->MaybeThrowOnDoGetSet($property, $setter, $props);
248
249 696
        /**
250
        * @var callable
251 696
        */
252
        $callable = [$this, TypeUtilities::MethodNameFromProperty($property, $setter)];
253 336
        $closure = Closure::fromCallable($callable);
254 252
255 336
        /**
256 336
        * @var scalar|array|object|null
257
        */
258
        $out = $closure->__invoke($v);
259 152
260 184
        return $out;
261 4
    }
262
}
263