Location   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 15
c 1
b 0
f 0
dl 0
loc 44
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A label() 0 3 1
A at() 0 6 2
A position() 0 3 1
A hasNegativeEdges() 0 8 3
A edges() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Pathfinder\Graph;
4
5
use Stratadox\Pathfinder\Position;
6
7
final class Location implements GeometricVertex
8
{
9
    private $position;
10
    private $label;
11
    private $edges;
12
13
    private function __construct(Position $position, string $label, Edges $edges)
14
    {
15
        $this->position = $position;
16
        $this->label = $label;
17
        $this->edges = $edges;
18
    }
19
20
    public static function at(
21
        Position $position,
22
        string $label,
23
        Edges $edges = null
24
    ): GeometricVertex {
25
        return new self($position, $label, $edges ?: Roads::none());
26
    }
27
28
    public function position(): Position
29
    {
30
        return $this->position;
31
    }
32
33
    public function label(): string
34
    {
35
        return $this->label;
36
    }
37
38
    public function edges(): Edges
39
    {
40
        return $this->edges;
41
    }
42
43
    public function hasNegativeEdges(): bool
44
    {
45
        foreach ($this->edges() as $edge) {
46
            if ($edge->cost() < 0) {
47
                return true;
48
            }
49
        }
50
        return false;
51
    }
52
}
53