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

ChildBottom::getHoleLeftIndex()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.074

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 10
ccs 5
cts 6
cp 0.8333
rs 9.2
cc 4
eloc 7
nc 3
nop 0
crap 4.074
1
<?php
2
namespace StefanoTree\NestedSet\MoveStrategy;
3
4
use StefanoTree\Exception;
5
6
class ChildBottom
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->isMovedDown()) {
22 3
            return $this->getSourceNode()->getLeft();
23 3
        } elseif ($this->isMovedUp()) {
24 3
            return $this->getSourceNode()->getLeft() + $this->getIndexShift();
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->isMovedDown()) {
33 3
            return $this->getSourceNode()->getRight();
34 3
        } elseif ($this->isMovedUp()) {
35 3
            return $this->getSourceNode()->getRight() + $this->getIndexShift();
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->isMovedDown()) {
44 3
            return $this->getTargetNode()->getRight() - $this->getSourceNode()->getLeft();
45 3
        } elseif ($this->isMovedUp()) {
46 3
            return $this->getTargetNode()->getRight() - $this->getSourceNode()->getRight() - 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()->getRight() - 1;
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
                $sourceNode->getRight() == ($targetNode->getRight() - 1)) ?
69 3
            true : false;
70
    }
71
}
72