GetIntNestedLevel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
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 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 8
    public static function DaftObjectExportableProperties() : array
108
    {
109 8
        return array_filter(
110 8
            parent::DaftObjectExportableProperties(),
111
            function (string $prop) : bool {
112 8
                return 'daftNestedObjectParentId' !== $prop;
113 8
            }
114
        );
115
    }
116
}
117