| Total Complexity | 9 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 5 | final class StaticPathfinder implements Pathfinder |
||
| 6 | { |
||
| 7 | private $index; |
||
| 8 | private $network; |
||
| 9 | |||
| 10 | private function __construct(ShortestPathForest $index, Network $network) |
||
| 14 | } |
||
| 15 | |||
| 16 | public static function using( |
||
| 17 | ShortestPathForest $index, |
||
| 18 | Network $network |
||
| 19 | ): Pathfinder { |
||
| 20 | return new self($index, $network); |
||
| 21 | } |
||
| 22 | |||
| 23 | public function from(string $start): array |
||
| 24 | { |
||
| 25 | if (!$this->network->has($start)) { |
||
| 26 | throw NonExistingStart::tried($start); |
||
| 27 | } |
||
| 28 | |||
| 29 | $paths = []; |
||
| 30 | foreach ($this->network->all() as $goal) { |
||
| 31 | if ($start !== $goal) { |
||
| 32 | try { |
||
| 33 | $paths[$goal] = $this->between($start, $goal); |
||
| 34 | } catch (NoPathAvailable $unreachableNode) { |
||
| 35 | // the node is not reachable: simply leave it out. |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 | return $paths; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function between(string $start, string $goal): array |
||
| 51 | } |
||
| 52 | } |
||
| 53 |