Total Complexity | 6 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
20 | final class MovesToFileRenderer implements SolutionRenderer |
||
21 | { |
||
22 | /** @var resource */ |
||
23 | private $output; |
||
24 | /** @var string */ |
||
25 | private $separator; |
||
26 | /** @var int */ |
||
27 | private $timeout; |
||
28 | |||
29 | private function __construct($outputStream, string $separator, int $timeout) |
||
35 | } |
||
36 | |||
37 | public static function fromFilenameAndSeparator( |
||
38 | string $fileName, |
||
39 | string $separator, |
||
40 | int $timeout = 0 |
||
41 | ): SolutionRenderer { |
||
42 | return new self(fopen($fileName, 'wb'), $separator, $timeout); |
||
43 | } |
||
44 | |||
45 | public function render(Solution $solution): void |
||
46 | { |
||
47 | foreach ($solution->moves() as $i => $move) { |
||
48 | if ($i) { |
||
49 | $this->log($this->separator); |
||
50 | } |
||
51 | $this->log((string) $move); |
||
52 | usleep($this->timeout); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | private function log(string $entry): void |
||
59 | } |
||
60 | } |
||
61 |