Passed
Push — changelog-new-format ( 262427...123313 )
by Jose
02:38
created

AbstractNode   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 2
cbo 1
dl 0
loc 90
ccs 27
cts 27
cp 1
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setParent() 0 4 1
A getParent() 0 4 1
A addChild() 0 6 1
A getChildren() 0 4 1
A getF() 0 4 1
A setG() 0 8 2
A getG() 0 4 1
A setH() 0 8 2
A getH() 0 4 1
1
<?php
2
3
namespace JMGQ\AStar;
4
5
abstract class AbstractNode implements Node
6
{
7
    private $parent;
8
    private $children = array();
9
10
    private $gScore;
11
    private $hScore;
12
13
    /**
14
     * {@inheritdoc}
15
     */
16 11
    public function setParent(Node $parent)
17
    {
18 11
        $this->parent = $parent;
19 11
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 12
    public function getParent()
25
    {
26 12
        return $this->parent;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 2
    public function addChild(Node $child)
33
    {
34 2
        $child->setParent($this);
35
36 2
        $this->children[] = $child;
37 2
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 2
    public function getChildren()
43
    {
44 2
        return $this->children;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 9
    public function getF()
51
    {
52 9
        return $this->getG() + $this->getH();
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 23
    public function setG($score)
59
    {
60 23
        if (!is_numeric($score)) {
61 7
            throw new \InvalidArgumentException('The G value is not a number');
62
        }
63
64 16
        $this->gScore = $score;
65 16
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 16
    public function getG()
71
    {
72 16
        return $this->gScore;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 23
    public function setH($score)
79
    {
80 23
        if (!is_numeric($score)) {
81 7
            throw new \InvalidArgumentException('The H value is not a number');
82
        }
83
84 16
        $this->hScore = $score;
85 16
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90 15
    public function getH()
91
    {
92 15
        return $this->hScore;
93
    }
94
}
95