Total Complexity | 5 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
21 | final class PuzzleStatesToFileRenderer implements SolutionRenderer |
||
22 | { |
||
23 | /** @var resource */ |
||
24 | private $output; |
||
25 | /** @var string */ |
||
26 | private $separator; |
||
27 | /** @var int */ |
||
28 | private $timeout; |
||
29 | |||
30 | private function __construct($outputStream, string $separator, int $timeout) |
||
31 | { |
||
32 | $this->output = $outputStream; |
||
33 | $this->separator = $separator; |
||
34 | $this->timeout = $timeout; |
||
35 | assert(is_resource($outputStream)); |
||
36 | } |
||
37 | |||
38 | public static function fromFilenameAndSeparator( |
||
39 | string $fileName, |
||
40 | string $separator, |
||
41 | int $timeout = 0 |
||
42 | ): SolutionRenderer { |
||
43 | return new self(fopen($fileName, 'wb'), $separator, $timeout); |
||
44 | } |
||
45 | |||
46 | public function render(Solution $solution): void |
||
47 | { |
||
48 | $puzzle = $solution->original(); |
||
49 | $this->log($puzzle->representation()); |
||
50 | usleep($this->timeout); |
||
51 | foreach ($solution->moves() as $move) { |
||
52 | $puzzle = $puzzle->afterMaking($move); |
||
53 | $this->log($this->separator); |
||
54 | $this->log($puzzle->representation()); |
||
55 | usleep($this->timeout); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | private function log(string $entry): void |
||
62 | } |
||
63 | } |
||
64 |