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

Bottom   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 2 Features 0
Metric Value
wmc 25
c 5
b 2
f 0
lcom 1
cbo 3
dl 0
loc 100
ccs 47
cts 47
cp 1
rs 10

9 Methods

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