Test Failed
Push — master ( 852abc...2f35aa )
by SignpostMarv
02:24
created

AbstractArrayBackedDaftNestedObject   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 129
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 129
ccs 49
cts 49
cp 1
rs 10
c 0
b 0
f 0
wmc 20

11 Methods

Rating   Name   Duplication   Size   Complexity  
A GetIntNestedRight() 0 3 1
A GetIntNestedLeft() 0 3 1
A GetIntNestedLevel() 0 3 1
A SetIntNestedLevel() 0 10 2
A SetIntNestedRight() 0 10 2
A SetIntNestedSortOrder() 0 10 2
A GetIntNestedSortOrder() 0 3 1
A ChangedProperties() 0 16 3
A ObtainDaftNestedObjectParentId() 0 15 1
A AlterDaftNestedObjectParentId() 0 19 4
A SetIntNestedLeft() 0 10 2
1
<?php
2
/**
3
* Base daft nested objects.
4
*
5
* @author SignpostMarv
6
*/
7
declare(strict_types=1);
8
9
namespace SignpostMarv\DaftObject;
10
11
abstract class AbstractArrayBackedDaftNestedObject extends AbstractArrayBackedDaftObject implements DaftNestedObject
12
{
13 22
    public function GetIntNestedLeft() : int
14
    {
15 22
        return (int) ($this->RetrievePropertyValueFromData('intNestedLeft') ?? null);
16
    }
17
18 22
    public function GetIntNestedRight() : int
19
    {
20 22
        return (int) ($this->RetrievePropertyValueFromData('intNestedRight') ?? null);
21
    }
22
23 22
    public function GetIntNestedLevel() : int
24
    {
25 22
        return (int) ($this->RetrievePropertyValueFromData('intNestedLevel') ?? null);
26
    }
27
28 4
    public function GetIntNestedSortOrder() : int
29
    {
30
        return (int) ($this->RetrievePropertyValueFromData('intNestedSortOrder') ?? null);
31
    }
32
33 4
    public function ObtainDaftNestedObjectParentId() : array
34
    {
35 4
        /**
36
        * @var string[]
37
        */
38
        $idProps = static::DaftNestedObjectParentIdProperties();
39
40 4
        return array_map(
41 4
            /**
42 4
            * @return mixed
43
            */
44
            function (string $prop) {
45
                return $this->$prop;
46 18
            },
47
            $idProps
48 18
        );
49 2
    }
50 2
51 2
    public function SetIntNestedLeft(int $value) : void
52
    {
53
        if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) {
54
            throw new ClassDoesNotImplementClassException(
55 16
                static::class,
56 16
                DaftNestedWriteableObject::class
57
            );
58 18
        }
59
60 18
        $this->NudgePropertyValue('intNestedLeft', $value);
61 2
    }
62 2
63 2
    public function SetIntNestedRight(int $value) : void
64
    {
65
        if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) {
66
            throw new ClassDoesNotImplementClassException(
67 16
                static::class,
68 16
                DaftNestedWriteableObject::class
69
            );
70 18
        }
71
72 18
        $this->NudgePropertyValue('intNestedRight', $value);
73 2
    }
74 2
75 2
    public function SetIntNestedLevel(int $value) : void
76
    {
77
        if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) {
78
            throw new ClassDoesNotImplementClassException(
79 16
                static::class,
80 16
                DaftNestedWriteableObject::class
81
            );
82
        }
83
84
        $this->NudgePropertyValue('intNestedLevel', $value);
85 14
    }
86
87 14
    public function SetIntNestedSortOrder(int $value) : void
88 2
    {
89 2
        if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) {
90 2
            throw new ClassDoesNotImplementClassException(
91
                static::class,
92
                DaftNestedWriteableObject::class
93
            );
94
        }
95
96
        $this->NudgePropertyValue('intNestedSortOrder', $value);
97 14
    }
98
99
    /**
100
    * @param mixed $value
101
    */
102 14
    public function AlterDaftNestedObjectParentId($value) : void
103 14
    {
104
        if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) {
105 14
            throw new ClassDoesNotImplementClassException(
106
                static::class,
107 2
                DaftNestedWriteableObject::class
108
            );
109 2
        }
110
111
        /**
112
        * @var string[] $props
113
        */
114 2
        $props = static::DaftNestedObjectParentIdProperties();
115 2
116 2
        /**
117
        * @var scalar $val
118 2
        */
119
        foreach (array_combine($props, (is_array($value) ? $value : [$value])) as $prop => $val) {
120
            $this->NudgePropertyValue($prop, $val);
121
        }
122 2
    }
123
124
    public function ChangedProperties() : array
125
    {
126
        $out = parent::ChangedProperties();
127
128
        /**
129
        * @var string $prop
130
        */
131
        foreach (static::DaftNestedObjectParentIdProperties() as $prop) {
132
            if (in_array($prop, $out, true)) {
133
                $out[] = 'daftNestedObjectParentId';
134
135
                break;
136
            }
137
        }
138
139
        return $out;
140
    }
141
}
142