Location::hasNegativeEdges()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 3
nc 3
nop 0
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