public function addMoney(Money $m) { if ($this->currency() == $m->currency()) { return new Money($this->amount() + $m->amount(), $this->currency()); } return MoneyBag::create($this, $m); }
/** * @param Money $money * @return bool */ private function isSameCurrency(Money $money) { return $this->currency()->equals($money->currency()); }
private function contains(Money $m) { $found = $this->findMoney($m->currency()); if ($found == NULL) { return FALSE; } return $found->amount() == $m->amount(); }
public function equals(Money $money) : bool { return $this->currency->equals($money->currency()) && $this->amount === $money->amount(); }
public function convert(Money $m, $to_currency, $round = 'down') { $factor = $this->get_factor($m->currency(), $to_currency); if ($factor === null) { throw new MoneyConversionException("no conversion for {$m->currency()} -> {$to_currency}"); } $units = Money::round($m->units() * $factor, $round); return new Money($units, $to_currency); }
public function isLessThan(Money $money) : bool { $this->ensureCurrenciesMatch($this->currency, $money->currency()); return $this->amount < $money->amount(); }