Passed
Push — master ( 6e67eb...aff4f7 )
by SignpostMarv
03:24
created

SetIntNestedLevel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
ccs 6
cts 6
cp 1
crap 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 120
    public function GetIntNestedLeft() : int
14
    {
15 120
        return (int) ($this->RetrievePropertyValueFromData('intNestedLeft') ?? null);
16
    }
17
18 120
    public function GetIntNestedRight() : int
19
    {
20 120
        return (int) ($this->RetrievePropertyValueFromData('intNestedRight') ?? null);
21
    }
22
23 120
    public function GetIntNestedLevel() : int
24
    {
25 120
        return (int) ($this->RetrievePropertyValueFromData('intNestedLevel') ?? null);
26
    }
27
28 120
    public function GetIntNestedSortOrder() : int
29
    {
30 120
        return (int) ($this->RetrievePropertyValueFromData('intNestedSortOrder') ?? null);
31
    }
32
33 62
    public function ObtainDaftNestedObjectParentId() : array
34
    {
35
        /**
36
        * @var string[]
37
        */
38 62
        $idProps = static::DaftNestedObjectParentIdProperties();
39
40 62
        return array_map(
41
            /**
42
            * @return mixed
43
            */
44
            function (string $prop) {
45 62
                return $this->$prop;
46 62
            },
47 62
            $idProps
48
        );
49
    }
50
51 116
    public function SetIntNestedLeft(int $value) : void
52
    {
53 116
        if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) {
54 2
            throw new ClassDoesNotImplementClassException(
55 2
                static::class,
56 2
                DaftNestedWriteableObject::class
57
            );
58
        }
59
60 114
        $this->NudgePropertyValue('intNestedLeft', $value);
61 114
    }
62
63 116
    public function SetIntNestedRight(int $value) : void
64
    {
65 116
        if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) {
66 2
            throw new ClassDoesNotImplementClassException(
67 2
                static::class,
68 2
                DaftNestedWriteableObject::class
69
            );
70
        }
71
72 114
        $this->NudgePropertyValue('intNestedRight', $value);
73 114
    }
74
75 66
    public function SetIntNestedLevel(int $value) : void
76
    {
77 66
        if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) {
78 2
            throw new ClassDoesNotImplementClassException(
79 2
                static::class,
80 2
                DaftNestedWriteableObject::class
81
            );
82
        }
83
84 64
        $this->NudgePropertyValue('intNestedLevel', $value);
85 64
    }
86
87 34
    public function SetIntNestedSortOrder(int $value) : void
88
    {
89 34
        if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) {
90 2
            throw new ClassDoesNotImplementClassException(
91 2
                static::class,
92 2
                DaftNestedWriteableObject::class
93
            );
94
        }
95
96 32
        $this->NudgePropertyValue('intNestedSortOrder', $value);
97 32
    }
98
99
    /**
100
    * @param mixed $value
101
    */
102 62
    public function AlterDaftNestedObjectParentId($value) : void
103
    {
104 62
        if ( ! is_a(static::class, DaftNestedWriteableObject::class, true)) {
105 2
            throw new ClassDoesNotImplementClassException(
106 2
                static::class,
107 2
                DaftNestedWriteableObject::class
108
            );
109
        }
110
111
        /**
112
        * @var string[] $props
113
        */
114 62
        $props = static::DaftNestedObjectParentIdProperties();
115
116
        /**
117
        * @var scalar $val
118
        */
119 62
        foreach (array_combine($props, (is_array($value) ? $value : [$value])) as $prop => $val) {
120 62
            $this->NudgePropertyValue($prop, $val);
121
        }
122 62
    }
123
124 2
    public function ChangedProperties() : array
125
    {
126 2
        $out = parent::ChangedProperties();
127
128
        /**
129
        * @var string $prop
130
        */
131 2
        foreach (static::DaftNestedObjectParentIdProperties() as $prop) {
132 2
            if (in_array($prop, $out, true)) {
133 2
                $out[] = 'daftNestedObjectParentId';
134
135 2
                break;
136
            }
137
        }
138
139 2
        return $out;
140
    }
141
}
142