Node::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Pathfinder\Graph;
4
5
final class Node implements Vertex
6
{
7
    private $label;
8
    private $edges;
9
10
    private function __construct(string $label, Edges $edges)
11
    {
12
        $this->label = $label;
13
        $this->edges = $edges;
14
    }
15
16
    public static function labeled(
17
        string $label,
18
        Edges $edges = null
19
    ): Vertex {
20
        return new self($label, $edges ?: Roads::none());
21
    }
22
23
    public function label(): string
24
    {
25
        return $this->label;
26
    }
27
28
    public function edges(): Edges
29
    {
30
        return $this->edges;
31
    }
32
33
    public function hasNegativeEdges(): bool
34
    {
35
        foreach ($this->edges() as $edge) {
36
            if ($edge->cost() < 0) {
37
                return true;
38
            }
39
        }
40
        return false;
41
    }
42
}
43