| Total Complexity | 8 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 10 | final class RiverCrossingPuzzle implements Puzzle |
||
| 11 | { |
||
| 12 | /** @var Farmer */ |
||
| 13 | private $farmer; |
||
| 14 | /** @var Moves */ |
||
| 15 | private $crossings; |
||
| 16 | |||
| 17 | private function __construct(Farmer $farmer, Moves $crossings) |
||
| 18 | { |
||
| 19 | $this->farmer = $farmer; |
||
| 20 | $this->crossings = $crossings; |
||
| 21 | } |
||
| 22 | |||
| 23 | public static function begin(): Puzzle |
||
| 24 | { |
||
| 25 | return new self(Farmer::withWolfGoatAndCabbage(), Moves::none()); |
||
| 26 | } |
||
| 27 | |||
| 28 | public function isSolved(): bool |
||
| 29 | { |
||
| 30 | return $this->farmer->hasMovedAllPurchasesAlong(); |
||
| 31 | } |
||
| 32 | |||
| 33 | public function movesSoFar(): Moves |
||
| 34 | { |
||
| 35 | return $this->crossings; |
||
| 36 | } |
||
| 37 | |||
| 38 | public function representation(): string |
||
| 39 | { |
||
| 40 | return (string) $this->farmer; |
||
| 41 | } |
||
| 42 | |||
| 43 | public function possibleMoves(): Moves |
||
| 44 | { |
||
| 45 | return $this->farmer->possibleCrossings(); |
||
| 46 | } |
||
| 47 | |||
| 48 | public function afterMaking(Move ...$moves): Puzzle |
||
| 57 | } |
||
| 58 | } |
||
| 59 |