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

()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 1
dl 0
loc 14
ccs 5
cts 5
cp 1
crap 3
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 scalar[] $value
38
    */
39 60
    public function SetDaftNestedObjectParentId(array $value) : void
40
    {
41
        /**
42
        * @var string[]
43
        */
44 60
        $props = static::DaftNestedObjectParentIdProperties();
45
46 60
        $propsAndVals = array_combine($props, $value);
47
48
        /**
49
        * @var array<string, scalar>
50
        */
51 60
        $propsAndVals = $propsAndVals;
0 ignored issues
show
Unused Code introduced by
The assignment to $propsAndVals is dead and can be removed.
Loading history...
52
53 60
        foreach (static::DaftNestedObjectParentIdProperties() as $i => $prop) {
54 60
            $this->NudgePropertyValue($prop, $value[$i] ?? null);
55
        }
56 60
    }
57
58
    /**
59
    * @return array<int, string>
60
    */
61
    abstract public static function DaftNestedObjectParentIdProperties() : array;
62
63
    /**
64
    * @see AbstractDaftObject::NudgePropertyValue()
65
    *
66
    * @param string $property property being nudged
67
    * @param scalar|array|object|null $value value to nudge property with
68
    */
69
    abstract protected function NudgePropertyValue(
70
        string $property,
71
        $value,
72
        bool $autoTrimStrings = AbstractArrayBackedDaftObject::BOOL_DEFAULT_AUTOTRIMSTRINGS,
73
        bool $throwIfNotUnique = AbstractArrayBackedDaftObject::BOOL_DEFAULT_THROWIFNOTUNIQUE
74
    ) : void;
75
}
76