Index   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 26
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A of() 0 3 1
A nextStepOnTheRoadBetween() 0 8 2
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Pathfinder;
4
5
final class Index implements ShortestPathForest
6
{
7
    private $nextNodeOnTheRoad;
8
9
    private function __construct(array $nextNodeOnTheRoad)
10
    {
11
        $this->nextNodeOnTheRoad = $nextNodeOnTheRoad;
12
    }
13
14
    /**
15
     * @param string[][] $nextNodeOnTheRoad
16
     * @return ShortestPathForest
17
     */
18
    public static function of(array $nextNodeOnTheRoad): ShortestPathForest
19
    {
20
        return new self($nextNodeOnTheRoad);
21
    }
22
23
    public function nextStepOnTheRoadBetween(
24
        string $start,
25
        string $goal
26
    ): string {
27
        if (isset($this->nextNodeOnTheRoad[$start][$goal])) {
28
            return $this->nextNodeOnTheRoad[$start][$goal];
29
        }
30
        throw NoSuchPath::between($start, $goal);
31
    }
32
}
33