GraphNetwork::withVertex()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Pathfinder\Graph\Builder;
4
5
use function array_merge;
6
use Stratadox\Pathfinder\Graph\Graph;
7
use Stratadox\Pathfinder\Graph\Node;
8
use Stratadox\Pathfinder\Network;
9
10
final class GraphNetwork
11
{
12
    private $nodes;
13
14
    private function __construct(Node ...$locations)
15
    {
16
        $this->nodes = $locations;
17
    }
18
19
    public static function create(): self
20
    {
21
        return new self();
22
    }
23
24
    public function withVertex(
25
        string $label,
26
        EdgeDefinition $edges
27
    ): self {
28
        return new self(...array_merge(
29
            $this->nodes,
30
            [Node::labeled($label, $edges->gather())]
31
        ));
32
    }
33
34
    public function make(): Network
35
    {
36
        return Graph::with(...$this->nodes);
37
    }
38
}
39