Conditions | 3 |
Paths | 3 |
Total Lines | 17 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
20 | public function fromString(string $puzzle): Puzzle |
||
21 | { |
||
22 | $network = []; |
||
23 | $data = json_decode($puzzle, true); |
||
24 | |||
25 | if (json_last_error() !== JSON_ERROR_NONE) { |
||
26 | throw InvalidFormat::couldNotLoad('network', $puzzle, json_last_error_msg()); |
||
27 | } |
||
28 | |||
29 | foreach ($data['edges'] as $edge) { |
||
30 | $network[$edge['from']][$edge['to']] = $edge['cost']; |
||
31 | } |
||
32 | |||
33 | return NetworkNavigationPuzzle::fromArrayAndStartAndGoal( |
||
34 | $network, |
||
35 | $data['start'], |
||
36 | $data['goal'] |
||
37 | ); |
||
40 |