| Total Complexity | 7 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | final class DijkstraWalker |
||
| 9 | { |
||
| 10 | private $builder; |
||
| 11 | |||
| 12 | private $dijkstra; |
||
| 13 | |||
| 14 | private $path; |
||
| 15 | |||
| 16 | private $map; |
||
| 17 | |||
| 18 | public function __construct( |
||
| 19 | DataMapper $builder, |
||
| 20 | Dijkstra $dijkstra |
||
| 21 | ) { |
||
| 22 | $this->builder = $builder; |
||
| 23 | $this->dijkstra = $dijkstra; |
||
| 24 | |||
| 25 | $this->init(); |
||
| 26 | } |
||
| 27 | |||
| 28 | public function buildPathBetween($start, $end) : bool |
||
| 29 | { |
||
| 30 | $this->builder->rebuildRelationMap(); |
||
| 31 | |||
| 32 | $shortestPath = $this->dijkstra->shortestPaths($start, $end); |
||
| 33 | $prevRelations = $this->map[$start]['relations']; |
||
| 34 | |||
| 35 | $this->path = '_embedded'; |
||
| 36 | |||
| 37 | foreach ($shortestPath[0] as $meta) { |
||
| 38 | if ($relationName = array_search($meta, $prevRelations)) { |
||
| 39 | $this->path .= '.' . $relationName; |
||
| 40 | } |
||
| 41 | |||
| 42 | $prevRelations = $this->map[$meta]['relations']; |
||
| 43 | } |
||
| 44 | |||
| 45 | return true; |
||
| 46 | } |
||
| 47 | |||
| 48 | public function getPath() : string |
||
| 57 | } |
||
| 58 | |||
| 59 | public function init() |
||
| 66 |