Conditions | 5 |
Paths | 5 |
Total Lines | 20 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
19 | public function fromString(string $puzzle): Puzzle |
||
20 | { |
||
21 | $puzzle = str_replace([' ', '|', '+', '-'], '', $puzzle); |
||
22 | $numbers = []; |
||
23 | foreach (preg_split("/(\n)|(\r)/", $puzzle) as $line) { |
||
24 | if (empty($line)) { |
||
25 | continue; |
||
26 | } |
||
27 | $row = []; |
||
28 | for ($c = 0; $c < 9; $c++) { |
||
29 | if ($line[$c] === '.') { |
||
30 | $row[] = null; |
||
31 | } else { |
||
32 | $row[] = (int) $line[$c]; |
||
33 | } |
||
34 | } |
||
35 | $numbers[] = $row; |
||
36 | } |
||
37 | assert(count($numbers) === 9); |
||
38 | return SudokuPuzzle::fromArrays(...$numbers); |
||
39 | } |
||
41 |