Completed
Push — master ( 2e5d0e...583994 )
by Bartko
06:02
created

ChildTop::makeHoleFromIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace StefanoTree\NestedSet\MoveStrategy;
3
4
use StefanoTree\Exception;
5
6
class ChildTop
7
    extends MoveStrategyAbstract
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
8
{
9 3
    public function getNewParentId()
10
    {
11 3
        return $this->getTargetNode()->getId();
12
    }
13
14 3
    public function getLevelShift()
15
    {
16 3
        return $this->getTargetNode()->getLevel() - $this->getSourceNode()->getLevel() + 1;
17
    }
18
19 3
    public function getHoleLeftIndex()
20
    {
21 3
        if ($this->isMovedToRoot() || $this->isMovedUp()) {
22 3
            return $this->getSourceNode()->getLeft() + $this->getIndexShift();
23 3
        } elseif ($this->isMovedDown()) {
24 3
            return $this->getSourceNode()->getLeft();
25
        } else {
26
            throw new Exception\BaseException('Cannot move node');
27
        }
28
    }
29
30 3
    public function getHoleRightIndex()
31
    {
32 3
        if ($this->isMovedToRoot() || $this->isMovedUp()) {
33 3
            return $this->getSourceNode()->getRight() + $this->getIndexShift();
34 3
        } elseif ($this->isMovedDown()) {
35 3
            return $this->getSourceNode()->getRight();
36
        } else {
37
            throw new Exception\BaseException('Cannot move node');
38
        }
39
    }
40
41 3
    public function getSourceNodeIndexShift()
42
    {
43 3
        if ($this->isMovedToRoot() || $this->isMovedUp()) {
44 3
            return $this->getTargetNode()->getLeft() - $this->getSourceNode()->getRight();
45 3
        } elseif ($this->isMovedDown()) {
46 3
            return $this->getTargetNode()->getLeft() - $this->getSourceNode()->getLeft() + 1;
47
        } else {
48
            throw new Exception\BaseException('Cannot move node');
49
        }
50
    }
51
52 3
    public function fixHoleFromIndex()
53
    {
54 3
        return $this->getSourceNode()->getRight();
55
    }
56
57 3
    public function makeHoleFromIndex()
58
    {
59 3
        return $this->getTargetNode()->getLeft();
60
    }
61
62 3
    public function isSourceNodeAtRequiredPosition()
63
    {
64 3
        $sourceNode = $this->getSourceNode();
65 3
        $targetNode = $this->getTargetNode();
66
67 3
        return ($sourceNode->getParentId() == $targetNode->getId() &&
68 3
                $targetNode->getLeft() == ($sourceNode->getLeft() - 1)) ?
69 3
            true : false;
70
    }
71
}
72