Completed
Push — develop ( 4ea5a3...a8c617 )
by Bartko
05:56
created

MoveStrategyAbstract   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 18
c 3
b 2
f 0
lcom 1
cbo 1
dl 0
loc 87
ccs 32
cts 32
cp 1
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getSourceNode() 0 4 1
A getTargetNode() 0 4 1
A isMovedUp() 0 5 2
A isMovedDown() 0 5 2
A isMovedToRoot() 0 6 3
A getIndexShift() 0 4 1
A canMoveBranch() 0 5 2
A isTargetNodeInsideSourceBranche() 0 9 3
A isTargetNodeRootNode() 0 5 2
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 15
    public function __construct(NodeInfo $sourceNode, NodeInfo $targetNode)
17
    {
18 15
        $this->sourceNode = $sourceNode;
19 15
        $this->targetNode = $targetNode;
20 15
    }
21
22
    /**
23
     * @return NodeInfo
24
     */
25 15
    protected function getSourceNode()
26
    {
27 15
        return $this->sourceNode;
28
    }
29
30
    /**
31
     * @return NodeInfo
32
     */
33 15
    protected function getTargetNode()
34
    {
35 15
        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 12
    protected function isMovedDown()
51
    {
52 12
        return ($this->getSourceNode()->getRight() < $this->getTargetNode()->getLeft()) ?
53 12
            true : false;
54
    }
55
56
    /**
57
     * @return boolean
58
     */
59 12
    protected function isMovedToRoot()
60
    {
61 12
        return ($this->getSourceNode()->getLeft() > $this->getTargetNode()->getLeft() &&
62 12
                    $this->getSourceNode()->getRight() < $this->getTargetNode()->getRight()) ?
63 12
            true : false;
64
    }
65
66 12
    public function getIndexShift()
67
    {
68 12
        return $this->getSourceNode()->getRight() - $this->getSourceNode()->getLeft() + 1;
69
    }
70
71 15
    public function canMoveBranch($rootNodeId)
72
    {
73 15
        return ($this->isTargetNodeInsideSourceBranche()) ?
74 15
            false : true;
75
    }
76
77 15
    protected function isTargetNodeInsideSourceBranche()
78
    {
79 15
        $targetNode = $this->getTargetNode();
80 15
        $sourceNode = $this->getSourceNode();
81
82 15
        return ($targetNode->getLeft() > $sourceNode->getLeft() &&
83 15
                $targetNode->getRight() < $sourceNode->getRight()) ?
84 15
            true : false;
85
    }
86
87 6
    protected function isTargetNodeRootNode($rootNodeId)
88
    {
89 6
        return ($rootNodeId == $this->getTargetNode()->getId()) ?
90 6
            true : false;
91
    }
92
}
93