Passed
Push — master ( 652f45...f3c04b )
by SignpostMarv
03:46
created

AbstractArrayBackedDaftNestedObject   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 83
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A GetIntNestedRight() 0 4 1
A GetIntNestedLeft() 0 4 1
A GetIntNestedSortOrder() 0 4 1
A ChangedProperties() 0 16 2
A GetDaftNestedObjectParentId() 0 20 1
A GetIntNestedLevel() 0 4 1
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
/**
12
* @template T as AbstractArrayBackedDaftNestedObject
13
*
14
* @template-implements DaftNestedObject<T>
15
*
16
* @property-read int $intNestedLeft
17
* @property-read int $intNestedRight
18
* @property-read int $intNestedLevel
19
* @property-read int $intNestedSortOrder
20
* @property-read scalar[] $daftNestedObjectParentId
21
*/
22
abstract class AbstractArrayBackedDaftNestedObject extends AbstractArrayBackedDaftObject implements DaftNestedObject
23
{
24
    /**
25
    * @use TraitSortableDaftObject<T>
26
    */
27
    use TraitSortableDaftObject;
28
29
    const COUNT_EXPECT_NON_EMPTY = 0;
30
31
    const SORTABLE_PROPERTIES = [
32
        'intNestedSortOrder',
33
    ];
34
35 92
    public function GetIntNestedLeft() : int
36
    {
37 92
        return NestedTypeParanoia::ForceInt(
38 92
            $this->RetrievePropertyValueFromData('intNestedLeft') ?? null
39
        );
40
    }
41
42 92
    public function GetIntNestedRight() : int
43
    {
44 92
        return NestedTypeParanoia::ForceInt(
45 92
            $this->RetrievePropertyValueFromData('intNestedRight') ?? null
46
        );
47
    }
48
49 92
    public function GetIntNestedLevel() : int
50
    {
51 92
        return NestedTypeParanoia::ForceInt(
52 92
            $this->RetrievePropertyValueFromData('intNestedLevel') ?? null
53
        );
54
    }
55
56 92
    public function GetIntNestedSortOrder() : int
57
    {
58 92
        return NestedTypeParanoia::ForceInt(
59 92
            $this->RetrievePropertyValueFromData('intNestedSortOrder') ?? null
60
        );
61
    }
62
63
    /**
64
    * @return scalar[]
65
    */
66 92
    public function GetDaftNestedObjectParentId() : array
67
    {
68
        /**
69
        * @var string[]
70
        */
71 92
        $idProps = static::DaftNestedObjectParentIdProperties();
72
73 92
        return array_map(
74
            /**
75
            * @return scalar
76
            */
77
            function (string $prop) {
78
                /**
79
                * @var scalar
80
                */
81 92
                $out = $this->__get($prop);
82
83 92
                return $out;
84 92
            },
85 92
            $idProps
86
        );
87
    }
88
89 2
    public function ChangedProperties() : array
90
    {
91 2
        $out = parent::ChangedProperties();
92
93 2
        $props = array_filter(
94 2
            static::DaftNestedObjectParentIdProperties(),
95
            function (string $prop) use ($out) : bool {
96 2
                return in_array($prop, $out, true);
97 2
            }
98
        );
99
100 2
        if (count($props) > self::COUNT_EXPECT_NON_EMPTY) {
101 2
            $out[] = 'daftNestedObjectParentId';
102
        }
103
104 2
        return $out;
105
    }
106
}
107