| Total Complexity | 7 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 9 | final class Farmer |
||
| 10 | { |
||
| 11 | /** @var Riverbank */ |
||
| 12 | private $currentBank; |
||
| 13 | /** @var Riverbank */ |
||
| 14 | private $otherBank; |
||
| 15 | |||
| 16 | public function __construct( |
||
| 17 | Riverbank $currentBank, |
||
| 18 | Riverbank $otherBank |
||
| 19 | ) { |
||
| 20 | $this->currentBank = $currentBank; |
||
| 21 | $this->otherBank = $otherBank; |
||
| 22 | } |
||
| 23 | |||
| 24 | public function hasMovedAllPurchasesAlong(): bool |
||
| 25 | { |
||
| 26 | return $this->currentBank->isGoal() && $this->currentBank->isFull(); |
||
| 27 | } |
||
| 28 | |||
| 29 | public static function withWolfGoatAndCabbage(): self |
||
| 30 | { |
||
| 31 | return new self( |
||
| 32 | new Riverbank(true, Purchase::cabbage(), Purchase::goat(), Purchase::wolf()), |
||
| 33 | new Riverbank(false) |
||
| 34 | ); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function possibleCrossings(): Moves |
||
| 42 | }); |
||
| 43 | } |
||
| 44 | |||
| 45 | public function after(Crossing $crossing): self |
||
| 46 | { |
||
| 47 | assert($this->currentBank->canTakeAway($crossing->bringAlong())); |
||
| 48 | return new self( |
||
| 49 | $this->otherBank->with($crossing->bringAlong()), |
||
| 50 | $this->currentBank->without($crossing->bringAlong()) |
||
| 51 | ); |
||
| 52 | } |
||
| 53 | |||
| 54 | public function __toString(): string |
||
| 60 | ); |
||
| 61 | } |
||
| 62 | } |
||
| 63 |