Node   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 12
c 1
b 0
f 0
dl 0
loc 36
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasNegativeEdges() 0 8 3
A label() 0 3 1
A __construct() 0 4 1
A edges() 0 3 1
A labeled() 0 5 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