Passed
Branch master (9026fd)
by Bartko
02:45
created

Top::makeHole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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