WithEdge::andTo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Pathfinder\Graph\Builder;
4
5
use Stratadox\Pathfinder\Graph\Edges;
6
use Stratadox\Pathfinder\Graph\Road;
7
use Stratadox\Pathfinder\Graph\Roads;
8
9
final class WithEdge implements EdgeDefinition
10
{
11
    private $targetLabel;
12
    private $edgeCost;
13
14
    private function __construct(string $targetLabel, float $edgeCost)
15
    {
16
        $this->targetLabel = $targetLabel;
17
        $this->edgeCost = $edgeCost;
18
    }
19
20
    public static function to(
21
        string $targetLabel,
22
        float $edgeCost = 1.0
23
    ): EdgeDefinition {
24
        return new self($targetLabel, $edgeCost);
25
    }
26
27
    public static function toTargets(
28
        string $targetLabel,
29
        string ...$moreLabels
30
    ): EdgeDefinition {
31
        $edge = self::to($targetLabel);
32
        foreach ($moreLabels as $label) {
33
            $edge = $edge->andTo($label);
34
        }
35
        return $edge;
36
    }
37
38
    public function andTo(string $target, float $cost = 1.0): EdgeDefinition
39
    {
40
        return MultipleEdges::consistingOf($this, WithEdge::to($target, $cost));
41
    }
42
43
    public function gather(): Edges
44
    {
45
        return Roads::available(
46
            Road::towards($this->targetLabel, $this->edgeCost)
47
        );
48
    }
49
}
50