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

Bottom::isSourceNodeAtRequiredPosition()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 3
eloc 6
nc 4
nop 0
crap 3
1
<?php
2
namespace StefanoTree\NestedSet\MoveStrategy;
3
4
use StefanoTree\Exception;
5
6
class Bottom
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 6
    public function getNewParentId()
10
    {
11 6
        return $this->getTargetNode()
12 6
                    ->getParentId();
13
    }
14
15 6
    public function getLevelShift()
16
    {
17 6
        return $this->getTargetNode()->getLevel() - $this->getSourceNode()->getLevel();
18
    }
19
20 6
    public function getHoleLeftIndex()
21
    {
22 6
        if ($this->isMovedToRoot() || $this->isMovedDown()) {
23 6
            return $this->getSourceNode()->getLeft();
24 3
        } elseif ($this->isMovedUp()) {
25 3
            return $this->getSourceNode()->getLeft() + $this->getIndexShift();
26
        } else {
27
            throw new Exception\BaseException('Cannot move node');
28
        }
29
    }
30
31 6
    public function getHoleRightIndex()
32
    {
33 6
        if ($this->isMovedToRoot() || $this->isMovedDown()) {
34 6
            return $this->getSourceNode()->getRight();
35 3
        } elseif ($this->isMovedUp()) {
36 3
            return $this->getSourceNode()->getRight() + $this->getIndexShift();
37
        } else {
38
            throw new Exception\BaseException('Cannot move node');
39
        }
40
    }
41
42 6
    public function getSourceNodeIndexShift()
43
    {
44 6
        if ($this->isMovedToRoot() || $this->isMovedDown()) {
45 6
            return $this->getTargetNode()->getRight() - $this->getSourceNode()->getLeft() + 1;
46 3
        } elseif ($this->isMovedUp()) {
47 3
            return $this->getTargetNode()->getRight() - $this->getSourceNode()->getLeft()
48 3
                + 1 - $this->getIndexShift();
49
        } else {
50
            throw new Exception\BaseException('Cannot move node');
51
        }
52
    }
53
54 6
    public function fixHoleFromIndex()
55
    {
56 6
        if ($this->isMovedToRoot() || $this->isMovedDown()) {
57 6
            return $this->getSourceNode()->getLeft();
58 3
        } elseif ($this->isMovedUp()) {
59 3
            return $this->getSourceNode()->getLeft() + $this->getIndexShift();
60
        } else {
61
            throw new Exception\BaseException('Cannot move node');
62
        }
63
    }
64
65 6
    public function makeHoleFromIndex()
66
    {
67 6
        return $this->getTargetNode()->getRight();
68
    }
69
70 9
    public function canMoveBranch()
71
    {
72 9
        if (false == parent::canMoveBranch()) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
73 3
            return false;
74
        }
75
76 6
        return ($this->getTargetNode()->isRoot()) ? false : true;
77
    }
78
79 6
    public function isSourceNodeAtRequiredPosition()
80
    {
81 6
        $sourceNode = $this->getSourceNode();
82 6
        $targetNode = $this->getTargetNode();
83
84 6
        return ($targetNode->getRight() == ($sourceNode->getLeft() - 1) &&
85 6
                $targetNode->getParentId() == $sourceNode->getParentId()) ?
86 6
            true : false;
87
    }
88
}
89