Returns a new Money object that represents
the difference of this and another Money object
public subtract ( |
||
$subtrahend | ||
return |
/** * Decrease this account current balance * * @param Money $amount * @throws InsufficientFunds * A member cannot withdraw more than it's account current balance */ public function withdraw(Money $amount) { if ($amount->greaterThan($this->balance)) { throw new InsufficientFunds("Cannot withdraw {$amount->getAmount()}"); } $this->balance = $this->balance->subtract($amount); }
/** * @expectedException Money\InvalidArgumentException */ public function testDifferentCurrenciesCannotBeSubtracted() { $m1 = new Money(100, new Currency('EUR')); $m2 = new Money(100, new Currency('USD')); $m1->subtract($m2); }
public function subtractFromAmount(Money $money) { return new static($this->amount->subtract($money), $this->dueDate); }
/** * @expectedException InvalidArgumentException */ public function testDifferentCurrenciesCannotBeSubtracted() { $m1 = new Money(100, CurrencyProxy::determine('EUR')); $m2 = new Money(100, CurrencyProxy::determine('USD')); $m1->subtract($m2); }
/** * @param Money $amount * * @throws \InvalidArgumentException * * @return Money */ public function subtract(Money $amount) : Money { return new self($this->money->subtract($amount->wrapped())); }