| Total Complexity | 6 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 21 | final class DebugLogger implements SearchStrategy |
||
| 22 | { |
||
| 23 | /** @var SearchStrategy */ |
||
| 24 | private $search; |
||
| 25 | /** @var int */ |
||
| 26 | private $timeout; |
||
| 27 | /** @var string */ |
||
| 28 | private $separator; |
||
| 29 | /** @var resource */ |
||
| 30 | private $output; |
||
| 31 | /** @var bool */ |
||
| 32 | private $isFirst = true; |
||
| 33 | |||
| 34 | public function __construct( |
||
| 35 | SearchStrategy $search, |
||
| 36 | int $timeout, |
||
| 37 | string $separator, |
||
| 38 | $outputStream |
||
| 39 | ) { |
||
| 40 | $this->search = $search; |
||
| 41 | $this->timeout = $timeout; |
||
| 42 | $this->separator = $separator; |
||
| 43 | assert(is_resource($outputStream)); |
||
| 44 | $this->output = $outputStream; |
||
| 45 | } |
||
| 46 | |||
| 47 | public function isOngoing(): bool |
||
| 48 | { |
||
| 49 | return $this->search->isOngoing(); |
||
| 50 | } |
||
| 51 | |||
| 52 | public function consider(Puzzle $puzzle): bool |
||
| 55 | } |
||
| 56 | |||
| 57 | public function nextCandidate(): Puzzle |
||
| 58 | { |
||
| 59 | $puzzle = $this->search->nextCandidate(); |
||
| 60 | if (!$this->isFirst) { |
||
| 61 | $this->log($this->separator); |
||
| 62 | } |
||
| 63 | $this->isFirst = false; |
||
| 64 | $this->log($puzzle->representation()); |
||
| 65 | usleep($this->timeout); |
||
| 66 | return $puzzle; |
||
| 67 | } |
||
| 68 | |||
| 69 | private function log(string $entry): void |
||
| 72 | } |
||
| 73 | } |
||
| 74 |