conferencetools /
checkin-module
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace ConferenceTools\Checkin\Domain\Process; |
||||
| 4 | |||||
| 5 | use Carnage\Cqrs\Aggregate\AbstractAggregate; |
||||
| 6 | use Carnage\Cqrs\Process\NewProcessInterface; |
||||
| 7 | use ConferenceTools\Checkin\Domain\Command\Delegate\RegisterDelegate; |
||||
| 8 | use ConferenceTools\Checkin\Domain\Command\Delegate\UpdateDelegateInformation; |
||||
| 9 | use ConferenceTools\Checkin\Domain\Event\Delegate\DelegateRegistered; |
||||
| 10 | use ConferenceTools\Checkin\Domain\Event\Purchase\TicketAssigned; |
||||
| 11 | use ConferenceTools\Checkin\Domain\Event\Purchase\TicketCreated; |
||||
| 12 | use ConferenceTools\Checkin\Domain\Event\Purchase\TicketPurchasePaid; |
||||
| 13 | use ConferenceTools\Checkin\Domain\ValueObject\DelegateInfo; |
||||
| 14 | |||||
| 15 | class ImportPurchase extends AbstractAggregate implements NewProcessInterface |
||||
| 16 | { |
||||
| 17 | /** |
||||
| 18 | * @var string |
||||
| 19 | */ |
||||
| 20 | private $purchaseId; |
||||
| 21 | |||||
| 22 | /** |
||||
| 23 | * @var bool |
||||
| 24 | */ |
||||
| 25 | private $paid = false; |
||||
| 26 | |||||
| 27 | /** |
||||
| 28 | * @var TicketAssigned[] |
||||
| 29 | */ |
||||
| 30 | private $tickets = []; |
||||
| 31 | |||||
| 32 | /** |
||||
| 33 | * @var string |
||||
| 34 | */ |
||||
| 35 | private $purchaserEmail; |
||||
| 36 | |||||
| 37 | /** |
||||
| 38 | * @var array |
||||
| 39 | */ |
||||
| 40 | private $delegates; |
||||
| 41 | |||||
| 42 | 7 | public static function withId(string $id) |
|||
| 43 | { |
||||
| 44 | 7 | $instance = new self; |
|||
| 45 | 7 | $instance->purchaseId = $id; |
|||
| 46 | 7 | return $instance; |
|||
| 47 | } |
||||
| 48 | |||||
| 49 | 7 | public function getId() |
|||
| 50 | { |
||||
| 51 | 7 | return $this->purchaseId; |
|||
| 52 | } |
||||
| 53 | |||||
| 54 | /* |
||||
| 55 | * @TODO handle events arriving out of order. |
||||
| 56 | */ |
||||
| 57 | 4 | public function ticketAssigned(TicketAssigned $event) |
|||
| 58 | { |
||||
| 59 | 4 | if (!$this->paid) { |
|||
| 60 | 3 | $this->apply($event); |
|||
| 61 | } else { |
||||
| 62 | 2 | $ticket = $event->getTicket(); |
|||
| 63 | 2 | $this->apply( |
|||
| 64 | 2 | new UpdateDelegateInformation( |
|||
| 65 | 2 | $this->delegates[$ticket->getPurchaseId()][$ticket->getTicketId()], |
|||
| 66 | 2 | $event->getDelegateInfo() |
|||
| 67 | ) |
||||
| 68 | ); |
||||
| 69 | } |
||||
| 70 | 4 | } |
|||
| 71 | |||||
| 72 | 2 | protected function applyUpdateDelegateInformation(UpdateDelegateInformation $command) |
|||
|
0 ignored issues
–
show
|
|||||
| 73 | { |
||||
| 74 | |||||
| 75 | 2 | } |
|||
| 76 | |||||
| 77 | 3 | protected function applyTicketAssigned(TicketAssigned $event) |
|||
| 78 | { |
||||
| 79 | 3 | $this->purchaseId = $event->getTicket()->getPurchaseId(); |
|||
| 80 | 3 | $this->tickets[$event->getTicket()->getTicketId()] = $event; |
|||
| 81 | 3 | } |
|||
| 82 | |||||
| 83 | 3 | public function ticketCreated(TicketCreated $event) |
|||
| 84 | { |
||||
| 85 | 3 | $this->apply($event); |
|||
| 86 | 3 | } |
|||
| 87 | |||||
| 88 | 3 | protected function applyTicketCreated(TicketCreated $event) |
|||
| 89 | { |
||||
| 90 | 3 | $this->tickets[$event->getTicket()->getTicketId()] = $event; |
|||
| 91 | 3 | } |
|||
| 92 | |||||
| 93 | 5 | public function ticketPurchasePaid(TicketPurchasePaid $event) |
|||
| 94 | { |
||||
| 95 | 5 | $this->apply($event); |
|||
| 96 | |||||
| 97 | 5 | foreach ($this->tickets as $ticket) { |
|||
| 98 | 4 | if ($ticket instanceof TicketAssigned) { |
|||
| 99 | 2 | $this->apply(new RegisterDelegate($ticket->getDelegateInfo(), $ticket->getTicket(), $this->purchaserEmail)); |
|||
| 100 | } else { |
||||
| 101 | 2 | $delegate = new DelegateInfo('', '', ''); |
|||
| 102 | 4 | $this->apply(new RegisterDelegate($delegate, $ticket->getTicket(), $this->purchaserEmail)); |
|||
| 103 | } |
||||
| 104 | } |
||||
| 105 | 5 | } |
|||
| 106 | |||||
| 107 | 5 | protected function applyTicketPurchasePaid(TicketPurchasePaid $event) |
|||
| 108 | { |
||||
| 109 | 5 | $this->purchaseId = $event->getPurchaseId(); |
|||
| 110 | 5 | $this->paid = true; |
|||
| 111 | 5 | $this->purchaserEmail = $event->getPurchaserEmail(); |
|||
| 112 | 5 | } |
|||
| 113 | |||||
| 114 | 4 | protected function applyRegisterDelegate(RegisterDelegate $command) |
|||
|
0 ignored issues
–
show
The parameter
$command is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 115 | { |
||||
| 116 | 4 | array_shift($this->tickets); |
|||
| 117 | 4 | } |
|||
| 118 | |||||
| 119 | 2 | public function delegateRegistered(DelegateRegistered $event) |
|||
| 120 | { |
||||
| 121 | 2 | $this->apply($event); |
|||
| 122 | 2 | } |
|||
| 123 | |||||
| 124 | 2 | protected function applyDelegateRegistered(DelegateRegistered $event) |
|||
| 125 | { |
||||
| 126 | 2 | $ticket = $event->getTicket(); |
|||
| 127 | 2 | $this->delegates[$ticket->getPurchaseId()][$ticket->getTicketId()] = $event->getDelegateId(); |
|||
| 128 | } |
||||
| 129 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.