Passed
Push — master ( eaacac...25b624 )
by SignpostMarv
03:26
created

WriteableObjectTrait::SetIntNestedLeft()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
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 DaftNestedWriteableObject
13
*/
14
trait WriteableObjectTrait
15
{
16 86
    public function SetIntNestedLeft(int $value) : void
17
    {
18 86
        $this->NudgePropertyValue('intNestedLeft', $value);
19 86
    }
20
21 86
    public function SetIntNestedRight(int $value) : void
22
    {
23 86
        $this->NudgePropertyValue('intNestedRight', $value);
24 86
    }
25
26 60
    public function SetIntNestedLevel(int $value) : void
27
    {
28 60
        $this->NudgePropertyValue('intNestedLevel', $value);
29 60
    }
30
31 28
    public function SetIntNestedSortOrder(int $value) : void
32
    {
33 28
        $this->NudgePropertyValue('intNestedSortOrder', $value);
34 28
    }
35
36
    /**
37
    * @param mixed $value
38
    */
39 60
    public function AlterDaftNestedObjectParentId($value) : void
40
    {
41
        /**
42
        * @var string[]
43
        */
44 60
        $props = static::DaftNestedObjectParentIdProperties();
45
46
        /**
47
        * @var array<string, scalar|array|object|null>
48
        */
49 60
        $propsAndVals = array_combine($props, (is_array($value) ? $value : [$value]));
50
51 60
        foreach ($propsAndVals as $prop => $val) {
52 60
            $this->NudgePropertyValue($prop, $val);
53
        }
54 60
    }
55
56
    /**
57
    * @return array<int, string>
58
    */
59
    abstract public static function DaftNestedObjectParentIdProperties() : array;
60
61
    /**
62
    * @see AbstractDaftObject::NudgePropertyValue()
63
    *
64
    * @param string $property property being nudged
65
    * @param scalar|array|object|null $value value to nudge property with
66
    */
67
    abstract protected function NudgePropertyValue(
68
        string $property,
69
        $value,
70
        bool $autoTrimStrings = AbstractArrayBackedDaftObject::BOOL_DEFAULT_AUTOTRIMSTRINGS,
71
        bool $throwIfNotUnique = AbstractArrayBackedDaftObject::BOOL_DEFAULT_THROWIFNOTUNIQUE
72
    ) : void;
73
}
74