subtract() public method

Returns a new Money object that represents the difference of this and another Money object
public subtract ( Money $subtrahend ) : Money
$subtrahend Money
return Money
Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 2
0
 /**
  * @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);
 }
Ejemplo n.º 4
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testDifferentCurrenciesCannotBeSubtracted()
 {
     $m1 = new Money(100, CurrencyProxy::determine('EUR'));
     $m2 = new Money(100, CurrencyProxy::determine('USD'));
     $m1->subtract($m2);
 }
Ejemplo n.º 5
0
 /**
  * @param Money $amount
  *
  * @throws \InvalidArgumentException
  *
  * @return Money
  */
 public function subtract(Money $amount) : Money
 {
     return new self($this->money->subtract($amount->wrapped()));
 }