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

AbstractNode::addChild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 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