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 ( b3c539...42e9ee )
by SignpostMarv
05:30
created

AbstractDaftObject::DaftObjectNullableProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
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
    * Does some sanity checking.
46
    *
47
    * @see DefinesOwnIdPropertiesInterface
48
    * @see TypeUtilities::CheckTypeDefinesOwnIdProperties()
49
    */
50 430
    public function __construct()
51
    {
52 430
        TypeUtilities::CheckTypeDefinesOwnIdProperties(
53 430
            static::class,
54 430
            ($this instanceof DefinesOwnIdPropertiesInterface)
55
        );
56 426
    }
57
58
    /**
59
    * @return mixed
60
    */
61 84
    public function __get(string $property)
62
    {
63 84
        return $this->DoGetSet($property, false);
64
    }
65
66
    /**
67
    * @param mixed $v
68
    */
69 160
    public function __set(string $property, $v) : void
70
    {
71 160
        $this->DoGetSet($property, true, $v);
72 152
    }
73
74
    /**
75
    * @see static::NudgePropertyValue()
76
    */
77 40
    public function __unset(string $property) : void
78
    {
79 40
        $this->NudgePropertyValue($property, null);
80 36
    }
81
82
    /**
83
    * @return array<string, mixed>
84
    */
85 62
    public function __debugInfo() : array
86
    {
87 62
        $getters = static::DaftObjectPublicGetters();
88 62
        $exportables = static::DaftObjectExportableProperties();
89
        /**
90
        * @var array<int, string> $properties
91
        */
92
        $properties = array_filter($exportables, function (string $prop) use ($getters) : bool {
93 60
            return $this->__isset($prop) && in_array($prop, $getters, true);
94 62
        });
95
96 62
        return array_combine($properties, array_map(
97
            /**
98
            * @return mixed
99
            */
100
            function (string $prop) {
101 48
                $expectedMethod = 'Get' . ucfirst($prop);
102
103 48
                return $this->$expectedMethod();
104 62
            },
105 62
            $properties
106
        ));
107
    }
108
109
    /**
110
    * List of properties that can be defined on an implementation.
111
    *
112
    * @return array<int, string>
113
    */
114 266
    final public static function DaftObjectProperties() : array
115
    {
116 266
        return static::PROPERTIES;
117
    }
118
119 92
    final public static function DaftObjectNullableProperties() : array
120
    {
121 92
        return static::NULLABLE_PROPERTIES;
122
    }
123
124 124
    final public static function DaftObjectExportableProperties() : array
125
    {
126 124
        return static::EXPORTABLE_PROPERTIES;
127
    }
128
129 110
    final public static function DaftObjectPublicGetters() : array
130
    {
131 110
        return TypeUtilities::DaftObjectPublicGetters(static::class);
132
    }
133
134 160
    final public static function DaftObjectPublicSetters() : array
135
    {
136 160
        return TypeUtilities::DaftObjectPublicSetters(static::class);
137
    }
138
139 68
    final public static function DaftObjectJsonProperties() : array
140
    {
141 68
        JsonTypeUtilities::ThrowIfNotDaftJson(static::class);
142
143 36
        return static::JSON_PROPERTIES;
144
    }
145
146 36
    final public static function DaftObjectJsonPropertyNames() : array
147
    {
148 36
        $out = [];
149
150 36
        foreach (static::DaftObjectJsonProperties() as $k => $prop) {
151 36
            if (is_string($k)) {
152 24
                $prop = $k;
153
            }
154
155 36
            $out[] = $prop;
156
        }
157
158 36
        return $out;
159
    }
160
161
    /**
162
    * Nudge the state of a given property, marking it as dirty.
163
    *
164
    * @param string $property property being nudged
165
    * @param mixed $value value to nudge property with
166
    *
167
    * @throws UndefinedPropertyException if $property is not in static::DaftObjectProperties()
168
    * @throws PropertyNotNullableException if $property is not in static::DaftObjectNullableProperties()
169
    * @throws PropertyNotRewriteableException if class is write-once read-many and $property was already changed
170
    */
171
    abstract protected function NudgePropertyValue(string $property, $value) : void;
172
173 218
    protected function MaybeThrowOnDoGetSet(string $property, bool $setter, array $props) : void
174
    {
175 218
        if (false === in_array($property, $props, true)) {
176 10
            if (false === in_array($property, static::DaftObjectProperties(), true)) {
177 6
                throw new UndefinedPropertyException(static::class, $property);
178 4
            } elseif ($setter) {
179 2
                throw new NotPublicSetterPropertyException(static::class, $property);
180
            }
181
182 2
            throw new NotPublicGetterPropertyException(static::class, $property);
183
        }
184 208
    }
185
186
    /**
187
    * @param mixed $v
188
    *
189
    * @return mixed
190
    */
191 218
    protected function DoGetSet(string $property, bool $setter, $v = null)
192
    {
193 218
        $props = $setter ? static::DaftObjectPublicSetters() : static::DaftObjectPublicGetters();
194
195 218
        $this->MaybeThrowOnDoGetSet($property, $setter, $props);
196
197 208
        return $this->{TypeUtilities::MethodNameFromProperty($property, $setter)}($v);
198
    }
199
}
200