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
Branch sortable (84ac62)
by SignpostMarv
02:18
created

DaftObjectExportableProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
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
* 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
    * Does some sanity checking.
53
    *
54
    * @see DefinesOwnIdPropertiesInterface
55
    * @see TypeUtilities::CheckTypeDefinesOwnIdProperties()
56
    */
57 466
    public function __construct()
58
    {
59 466
        TypeUtilities::CheckTypeDefinesOwnIdProperties(
60 466
            static::class,
61 466
            ($this instanceof DefinesOwnIdPropertiesInterface)
62
        );
63 462
    }
64
65
    /**
66
    * @return mixed
67
    */
68 90
    public function __get(string $property)
69
    {
70 90
        return $this->DoGetSet($property, false);
71
    }
72
73
    /**
74
    * @param mixed $v
75
    */
76 166
    public function __set(string $property, $v) : void
77
    {
78 166
        $this->DoGetSet($property, true, $v);
79 158
    }
80
81
    /**
82
    * @see static::NudgePropertyValue()
83
    */
84 46
    public function __unset(string $property) : void
85
    {
86 46
        $this->NudgePropertyValue($property, null);
87 42
    }
88
89
    /**
90
    * @return array<string, mixed>
91
    */
92 68
    public function __debugInfo() : array
93
    {
94 68
        $getters = static::DaftObjectPublicGetters();
95 68
        $exportables = static::DaftObjectExportableProperties();
96
        /**
97
        * @var array<int, string> $properties
98
        */
99
        $properties = array_filter($exportables, function (string $prop) use ($getters) : bool {
100 66
            return $this->__isset($prop) && in_array($prop, $getters, true);
101 68
        });
102
103 68
        return array_combine($properties, array_map(
104
            /**
105
            * @return mixed
106
            */
107
            function (string $prop) {
108 54
                $expectedMethod = 'Get' . ucfirst($prop);
109
110 54
                return $this->$expectedMethod();
111 68
            },
112 68
            $properties
113
        ));
114
    }
115
116 2
    public function CompareToDaftSortableObject(DaftSortableObject $otherObject) : int
117
    {
118 2
        if ( ! is_a(static::class, DaftSortableObject::class, true)) {
119
            throw new ClassDoesNotImplementClassException(
120
                static::class,
121
                DaftSortableObject::class
122
            );
123
        }
124
125
        /**
126
        * @var string $property
127
        */
128 2
        foreach (static::DaftSortableObjectProperties() as $property) {
129 2
            $method = 'Get' . $property;
130 2
            $sort = $this->$method() <=> $otherObject->$method();
131
132 2
            if (0 !== $sort) {
133 2
                return $sort;
134
            }
135
        }
136
137 2
        return 0;
138
    }
139
140
    /**
141
    * List of properties that can be defined on an implementation.
142
    *
143
    * @return array<int, string>
144
    */
145 294
    final public static function DaftObjectProperties() : array
146
    {
147
        /**
148
        * @var array<int, string> $out
149
        */
150 294
        $out = static::PROPERTIES;
151
152 294
        return $out;
153
    }
154
155 102
    final public static function DaftObjectNullableProperties() : array
156
    {
157
        /**
158
        * @var array<int, string> $out
159
        */
160 102
        $out = static::NULLABLE_PROPERTIES;
161
162 102
        return $out;
163
    }
164
165 134
    final public static function DaftObjectExportableProperties() : array
166
    {
167
        /**
168
        * @var array<int, string> $out
169
        */
170 134
        $out = static::EXPORTABLE_PROPERTIES;
171
172 134
        return $out;
173
    }
174
175 116
    final public static function DaftObjectPublicGetters() : array
176
    {
177 116
        return TypeUtilities::DaftObjectPublicGetters(static::class);
178
    }
179
180
    final public static function DaftObjectPublicOrProtectedGetters() : array
181
    {
182
        return TypeUtilities::DaftObjectPublicOrProtectedGetters(static::class);
183
    }
184
185 166
    final public static function DaftObjectPublicSetters() : array
186
    {
187 166
        return TypeUtilities::DaftObjectPublicSetters(static::class);
188
    }
189
190 74
    final public static function DaftObjectJsonProperties() : array
191
    {
192 74
        JsonTypeUtilities::ThrowIfNotDaftJson(static::class);
193
194
        /**
195
        * @var array<int|string, string> $out
196
        */
197 36
        $out = static::JSON_PROPERTIES;
198
199 36
        return $out;
200
    }
201
202 36
    final public static function DaftObjectJsonPropertyNames() : array
203
    {
204 36
        $out = [];
205
206
        /**
207
        * @var array<int|string, string> $jsonProperties
208
        */
209 36
        $jsonProperties = static::DaftObjectJsonProperties();
210
211 36
        foreach ($jsonProperties as $k => $prop) {
212 36
            if (is_string($k)) {
213 24
                $prop = $k;
214
            }
215
216 36
            $out[] = $prop;
217
        }
218
219 36
        return $out;
220
    }
221
222 2
    public static function DaftSortableObjectProperties() : array
223
    {
224 2
        if ( ! is_a(static::class, DaftSortableObject::class, true)) {
225
            throw new ClassDoesNotImplementClassException(
226
                static::class,
227
                DaftSortableObject::class
228
            );
229
        }
230
231
        /**
232
        * @var array<int, string> $out
233
        */
234 2
        $out = static::SORTABLE_PROPERTIES;
235
236 2
        return $out;
237
    }
238
239
    /**
240
    * Nudge the state of a given property, marking it as dirty.
241
    *
242
    * @param string $property property being nudged
243
    * @param scalar|null|array|object $value value to nudge property with
244
    *
245
    * @throws UndefinedPropertyException if $property is not in static::DaftObjectProperties()
246
    * @throws PropertyNotNullableException if $property is not in static::DaftObjectNullableProperties()
247
    * @throws PropertyNotRewriteableException if class is write-once read-many and $property was already changed
248
    */
249
    abstract protected function NudgePropertyValue(string $property, $value) : void;
250
251 224
    protected function MaybeThrowOnDoGetSet(string $property, bool $setter, array $props) : void
252
    {
253 224
        if (false === in_array($property, $props, true)) {
254 10
            if (false === in_array($property, static::DaftObjectProperties(), true)) {
255 6
                throw new UndefinedPropertyException(static::class, $property);
256 4
            } elseif ($setter) {
257 2
                throw new NotPublicSetterPropertyException(static::class, $property);
258
            }
259
260 2
            throw new NotPublicGetterPropertyException(static::class, $property);
261
        }
262 214
    }
263
264
    /**
265
    * @param mixed $v
266
    *
267
    * @return mixed
268
    */
269 224
    protected function DoGetSet(string $property, bool $setter, $v = null)
270
    {
271 224
        $props = $setter ? static::DaftObjectPublicSetters() : static::DaftObjectPublicGetters();
272
273 224
        $this->MaybeThrowOnDoGetSet($property, $setter, $props);
274
275 214
        return $this->{TypeUtilities::MethodNameFromProperty($property, $setter)}($v);
276
    }
277
}
278