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

WriteableObjectTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 61
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A SetIntNestedLevel() 0 3 1
A SetIntNestedRight() 0 3 1
A SetIntNestedSortOrder() 0 3 1
A SetIntNestedLeft() 0 3 1
A SetDaftNestedObjectParentId() 0 16 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
/**
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