Passed
Push — master ( 152a70...0c8393 )
by Jose
03:00
created

NodeHashTable::isEmpty()   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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace JMGQ\AStar;
4
5
class NodeHashTable implements \IteratorAggregate, NodeCollectionInterface
6
{
7
    /** @var Node[] */
8
    private array $nodes = [];
9
10
    /**
11
     * {@inheritdoc}
12
     */
13 7
    public function getIterator(): iterable
14
    {
15 7
        return new \ArrayIterator($this->nodes);
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21 13
    public function extractBest(): ?Node
22
    {
23 13
        $bestNode = null;
24
25 13
        foreach ($this->nodes as $node) {
26 13
            if ($bestNode === null || $node->getF() < $bestNode->getF()) {
0 ignored issues
show
Bug introduced by
The method getF() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
            if ($bestNode === null || $node->getF() < $bestNode->/** @scrutinizer ignore-call */ getF()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27 13
                $bestNode = $node;
28
            }
29
        }
30
31 13
        if ($bestNode !== null) {
32 13
            $this->remove($bestNode);
33
        }
34
35 13
        return $bestNode;
36
    }
37
38 10
    public function get(string $nodeId): ?Node
39
    {
40 10
        return $this->nodes[$nodeId] ?? null;
41
    }
42
43 20
    public function add(Node $node): void
44
    {
45 20
        $this->nodes[$node->getId()] = $node;
46 20
    }
47
48 14
    public function remove(Node $node): void
49
    {
50 14
        unset($this->nodes[$node->getId()]);
51 14
    }
52
53 13
    public function isEmpty(): bool
54
    {
55 13
        return empty($this->nodes);
56
    }
57
58 10
    public function contains(Node $node): bool
59
    {
60 10
        return isset($this->nodes[$node->getId()]);
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 13
    public function clear(): void
67
    {
68 13
        $this->nodes = [];
69 13
    }
70
}
71