Total Complexity | 10 |
Total Lines | 60 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
5 | class Graph |
||
6 | { |
||
7 | /** @var Link[] */ |
||
8 | private array $links = []; |
||
9 | |||
10 | /** |
||
11 | * @param Link[] $links |
||
12 | */ |
||
13 | 15 | public function __construct(iterable $links = []) |
|
14 | { |
||
15 | 15 | foreach ($links as $link) { |
|
16 | 11 | $this->addLink($link); |
|
17 | } |
||
18 | 15 | } |
|
19 | |||
20 | 14 | public function addLink(Link $link): void |
|
21 | { |
||
22 | 14 | $linkId = $this->getLinkId($link->getSource(), $link->getDestination()); |
|
23 | |||
24 | 14 | $this->links[$linkId] = $link; |
|
25 | 14 | } |
|
26 | |||
27 | 8 | public function getLink(Coordinate $source, Coordinate $destination): ?Link |
|
28 | { |
||
29 | 8 | if ($this->hasLink($source, $destination)) { |
|
30 | 8 | $linkId = $this->getLinkId($source, $destination); |
|
31 | |||
32 | 8 | return $this->links[$linkId]; |
|
33 | } |
||
34 | |||
35 | 3 | return null; |
|
36 | } |
||
37 | |||
38 | 9 | public function hasLink(Coordinate $source, Coordinate $destination): bool |
|
39 | { |
||
40 | 9 | $linkId = $this->getLinkId($source, $destination); |
|
41 | |||
42 | 9 | return isset($this->links[$linkId]); |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * @param Coordinate $node |
||
47 | * @return Coordinate[] |
||
48 | */ |
||
49 | 5 | public function getDirectSuccessors(Coordinate $node): array |
|
60 | } |
||
61 | |||
62 | 14 | private function getLinkId(Coordinate $source, Coordinate $destination): string |
|
63 | { |
||
65 | } |
||
66 | } |
||
67 |