Passed
Push — master ( 979da0...21dcf7 )
by Jesse
01:38
created

PathRetracer::retrace()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Pathfinder\Reconstruction;
4
5
final class PathRetracer
6
{
7
    public function retrace(
8
        string $start,
9
        string $goal,
10
        array $breadcrumbs
11
    ): array {
12
        $node = $goal;
13
        $path = [];
14
        while (isset($breadcrumbs[$node])) {
15
            $path[] = $node;
16
            $node = $breadcrumbs[$node];
17
        }
18
        $path[] = $start;
19
        return array_reverse($path);
20
    }
21
}
22