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

MoveStrategyAbstract::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
namespace StefanoTree\NestedSet\MoveStrategy;
3
4
use StefanoTree\NestedSet\NodeInfo;
5
6
abstract class MoveStrategyAbstract
7
    implements MoveStrategyInterface
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
8
{
9
    protected $sourceNode;
10
    protected $targetNode;
11
12
    /**
13
     * @param NodeInfo $sourceNode
14
     * @param NodeInfo $targetNode
15
     */
16 18
    public function __construct(NodeInfo $sourceNode, NodeInfo $targetNode)
17
    {
18 18
        $this->sourceNode = $sourceNode;
19 18
        $this->targetNode = $targetNode;
20 18
    }
21
22
    /**
23
     * @return NodeInfo
24
     */
25 18
    protected function getSourceNode()
26
    {
27 18
        return $this->sourceNode;
28
    }
29
30
    /**
31
     * @return NodeInfo
32
     */
33 18
    protected function getTargetNode()
34
    {
35 18
        return $this->targetNode;
36
    }
37
38
    /**
39
     * @return boolean
40
     */
41 12
    protected function isMovedUp()
42
    {
43 12
        return ($this->getTargetNode()->getRight() < $this->getSourceNode()->getLeft()) ?
44 12
            true : false;
45
    }
46
47
    /**
48
     * @return boolean
49
     */
50 15
    protected function isMovedDown()
51
    {
52 15
        return ($this->getSourceNode()->getRight() < $this->getTargetNode()->getLeft()) ?
53 15
            true : false;
54
    }
55
56
    /**
57
     * @return boolean
58
     */
59 15
    protected function isMovedToRoot()
60
    {
61 15
        return ($this->getSourceNode()->getLeft() > $this->getTargetNode()->getLeft() &&
62 15
                    $this->getSourceNode()->getRight() < $this->getTargetNode()->getRight()) ?
63 15
            true : false;
64
    }
65
66 15
    public function getIndexShift()
67
    {
68 15
        return $this->getSourceNode()->getRight() - $this->getSourceNode()->getLeft() + 1;
69
    }
70
71 18
    public function canMoveBranch()
72
    {
73 18
        return ($this->isTargetNodeInsideSourceBranch()) ?
74 18
            false : true;
75
    }
76
77 18
    protected function isTargetNodeInsideSourceBranch()
78
    {
79 18
        $targetNode = $this->getTargetNode();
80 18
        $sourceNode = $this->getSourceNode();
81
82 18
        return ($targetNode->getLeft() > $sourceNode->getLeft() &&
83 18
                $targetNode->getRight() < $sourceNode->getRight()) ?
84 18
            true : false;
85
    }
86
}
87