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

ChildTop   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 90.63%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 19
c 4
b 1
f 0
lcom 1
cbo 3
dl 0
loc 66
ccs 29
cts 32
cp 0.9063
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getNewParentId() 0 4 1
A getLevelShift() 0 4 1
A getHoleLeftIndex() 0 10 4
A getHoleRightIndex() 0 10 4
A getSourceNodeIndexShift() 0 10 4
A fixHoleFromIndex() 0 4 1
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 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