Passed
Push — master ( 0c8393...d0b1a8 )
by Jose
02:37
created

Node::getG()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace JMGQ\AStar\Node;
4
5
/**
6
 * @internal
7
 */
8
class Node
9
{
10
    private mixed $state;
11
    private string $id;
12
    private ?Node $parent = null;
13
    private float | int $gScore;
14
    private float | int $hScore;
15
16
    /**
17
     * @param mixed $state The state refers to the actual user data that represents a node in the user's business logic.
18
     */
19 40
    public function __construct(mixed $state)
20
    {
21 40
        $this->state = $state;
22 40
        $this->id = $state instanceof NodeIdentifierInterface ? $state->getUniqueNodeId() : serialize($state);
23 40
    }
24
25
    /**
26
     * @return mixed Returns the state, which is the user data that represents a node in the user's business logic.
27
     */
28 13
    public function getState(): mixed
29
    {
30 13
        return $this->state;
31
    }
32
33 14
    public function getId(): string
34
    {
35 14
        return $this->id;
36
    }
37
38 10
    public function setParent(Node $parent): void
39
    {
40 10
        $this->parent = $parent;
41 10
    }
42
43 13
    public function getParent(): ?Node
44
    {
45 13
        return $this->parent;
46
    }
47
48 9
    public function getF(): float | int
49
    {
50 9
        return $this->getG() + $this->getH();
51
    }
52
53 19
    public function setG(float | int $score): void
54
    {
55 19
        $this->gScore = $score;
56 19
    }
57
58 16
    public function getG(): float | int
59
    {
60 16
        return $this->gScore;
61
    }
62
63 19
    public function setH(float | int $score): void
64
    {
65 19
        $this->hScore = $score;
66 19
    }
67
68 15
    public function getH(): float | int
69
    {
70 15
        return $this->hScore;
71
    }
72
}
73