public function withdraw(Withdraw $withdraw) { if ($this->balance < $withdraw->getAmount()) { throw new \InvalidArgumentException('Trying to withdraw greater amount than current balance'); } $this->applyMoneyWereWithdrawnEvent($this->record(new MoneyWereWithdrawnEvent($this->number, $withdraw))); }
public function __construct(AccountNumber $accountNumber, Withdraw $withdraw) { $this->accountNumber = (string) $accountNumber; $this->transaction = (string) $withdraw->getTransaction(); $this->amount = (int) $withdraw->getAmount(); $this->identifier = uniqid(); $this->recordedOn = microtime(true); }