| Conditions | 6 |
| Paths | 10 |
| Total Lines | 21 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 32 | public function fromString(string $maze): Puzzle |
||
| 33 | { |
||
| 34 | $walls = []; |
||
| 35 | $goal = null; |
||
| 36 | $hero = null; |
||
| 37 | foreach (preg_split("/(\n)|(\r)/", $maze) as $y => $line) { |
||
| 38 | foreach (str_split($line) as $x => $char) { |
||
| 39 | if ($char === $this->wall) { |
||
| 40 | $walls[] = new Wall($x, $y); |
||
| 41 | } |
||
| 42 | if ($char === $this->goal) { |
||
| 43 | $goal = new Goal($x, $y); |
||
| 44 | } |
||
| 45 | if ($char === $this->hero) { |
||
| 46 | $hero = new Hero($x, $y); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | } |
||
| 50 | assert(null !== $goal); |
||
| 51 | assert(null !== $hero); |
||
| 52 | return MazePuzzle::withHeroAndMaze($hero, Maze::withGoalAndWalls($goal, ...$walls)); |
||
| 53 | } |
||
| 55 |