WithEdge   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 1
b 0
f 0
dl 0
loc 38
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A to() 0 5 1
A gather() 0 4 1
A __construct() 0 4 1
A toTargets() 0 9 2
A andTo() 0 3 1
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