Completed
Push — master ( cc8038...edef00 )
by Bartko
01:27
created

Bottom::canCreateNewNode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace StefanoTree\NestedSet\AddStrategy;
6
7
use StefanoTree\Exception\ValidationException;
8
use StefanoTree\NestedSet\NodeInfo;
9
10
class Bottom extends AddStrategyAbstract
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected function canCreateNewNode(NodeInfo $targetNode): void
16
    {
17
        if ($targetNode->isRoot()) {
18
            throw new ValidationException('Cannot create node. Target node is root. Root node cannot have sibling.');
19
        }
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    protected function makeHole(NodeInfo $targetNode): void
26
    {
27
        $moveFromIndex = $targetNode->getRight();
28
        $this->getManipulator()->moveLeftIndexes($moveFromIndex, 2, $targetNode->getScope());
29
        $this->getManipulator()->moveRightIndexes($moveFromIndex, 2, $targetNode->getScope());
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    protected function createNewNodeNodeInfo(NodeInfo $targetNode): NodeInfo
36
    {
37
        return new NodeInfo(
38
            null,
39
            $targetNode->getParentId(),
40
            $targetNode->getLevel(),
41
            $targetNode->getRight() + 1,
42
            $targetNode->getRight() + 2,
43
            $targetNode->getScope()
44
        );
45
    }
46
}
47