| Conditions | 4 |
| Paths | 3 |
| Total Lines | 28 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 27 | public function handle(Command $command): void |
||
| 28 | { |
||
| 29 | assert($command instanceof AcceptTheProposal); |
||
| 30 | |||
| 31 | $proposal = $this->proposals->withId($command->proposal()); |
||
| 32 | if (!$proposal || !$command->acceptingPlayer()->is($proposal->proposedTo())) { |
||
| 33 | $this->eventBag->add( |
||
| 34 | new TriedAcceptingUnknownProposal( |
||
| 35 | $command->correlationId(), |
||
| 36 | 'Proposal not found' |
||
| 37 | ) |
||
| 38 | ); |
||
| 39 | return; |
||
| 40 | } |
||
| 41 | |||
| 42 | try { |
||
| 43 | $proposal->accept($this->clock->now()); |
||
| 44 | } catch (ProposalHasAlreadyExpired $weAreTooLate) { |
||
| 45 | $this->eventBag->add( |
||
| 46 | new TriedAcceptingExpiredProposal( |
||
| 47 | $command->correlationId(), |
||
| 48 | $weAreTooLate->getMessage() |
||
| 49 | ) |
||
| 50 | ); |
||
| 51 | return; |
||
| 52 | } |
||
| 53 | |||
| 54 | $this->eventBag->takeFrom($proposal); |
||
| 55 | } |
||
| 57 |