Completed
Push — develop ( 32afc4...f78f16 )
by Bartko
03:00
created

ChildBottom   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 22
c 3
b 1
f 0
lcom 1
cbo 3
dl 0
loc 88
ccs 40
cts 40
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getNewParentId() 0 4 1
A getLevelShift() 0 4 1
A getHoleLeftIndex() 0 14 4
A getHoleRightIndex() 0 14 4
A getSourceNodeIndexShift() 0 14 4
A fixHoleFromIndex() 0 14 4
A makeHoleFromIndex() 0 4 1
A isSourceNodeAtRequiredPosition() 0 9 3
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()) {
22 3
            return $this->getSourceNode()->getLeft();
23 3
        } elseif ($this->isMovedUp()) {
24 3
            return $this->getSourceNode()->getLeft() + $this->getIndexShift();
25 3
        } elseif ($this->isMovedDown()) {
26 3
            return $this->getSourceNode()->getLeft();
27
        } else {
28
            // @codeCoverageIgnoreStart
29
            throw new Exception\BaseException('Cannot move node');
30
            // @codeCoverageIgnoreEnd
31
        }
32
    }
33
34 3
    public function getHoleRightIndex()
35
    {
36 3
        if ($this->isMovedToRoot()) {
37 3
            return $this->getSourceNode()->getRight();
38 3
        } elseif ($this->isMovedUp()) {
39 3
            return $this->getSourceNode()->getRight() + $this->getIndexShift();
40 3
        } elseif ($this->isMovedDown()) {
41 3
            return $this->getSourceNode()->getRight();
42
        } else {
43
            // @codeCoverageIgnoreStart
44
            throw new Exception\BaseException('Cannot move node');
45
            // @codeCoverageIgnoreEnd
46
        }
47
    }
48
49 3
    public function getSourceNodeIndexShift()
50
    {
51 3
        if ($this->isMovedToRoot()) {
52 3
            return $this->getTargetNode()->getRight() - $this->getSourceNode()->getLeft();
53 3
        } elseif ($this->isMovedUp()) {
54 3
            return $this->getTargetNode()->getRight() - $this->getSourceNode()->getRight() - 1;
55 3
        } elseif ($this->isMovedDown()) {
56 3
            return $this->getTargetNode()->getRight() - $this->getSourceNode()->getLeft();
57
        } else {
58
            // @codeCoverageIgnoreStart
59
            throw new Exception\BaseException('Cannot move node');
60
            // @codeCoverageIgnoreEnd
61
        }
62
    }
63
64 3
    public function fixHoleFromIndex()
65
    {
66 3
        if ($this->isMovedToRoot()) {
67 3
            return $this->getSourceNode()->getRight();
68 3
        } elseif ($this->isMovedUp()) {
69 3
            return $this->getSourceNode()->getRight();
70 3
        } elseif ($this->isMovedDown()) {
71 3
            return $this->getSourceNode()->getRight();
72
        } else {
73
            // @codeCoverageIgnoreStart
74
            throw new Exception\BaseException('Cannot move node');
75
            // @codeCoverageIgnoreEnd
76
        }
77
    }
78
79 3
    public function makeHoleFromIndex()
80
    {
81 3
        return $this->getTargetNode()->getRight() - 1;
82
    }
83
84 3
    public function isSourceNodeAtRequiredPosition()
85
    {
86 3
        $sourceNode = $this->getSourceNode();
87 3
        $targetNode = $this->getTargetNode();
88
89 3
        return ($sourceNode->getParentId() == $targetNode->getId() &&
90 3
                $sourceNode->getRight() == ($targetNode->getRight() - 1)) ?
91 3
            true : false;
92
    }
93
}
94