/** * Formats a Money object using PHP's built-in NumberFormatter. * * @param Money $money * @return string */ public function format(Money $money = null) { if (!$money) { return null; } else { return $this->numberFormatter->formatCurrency($money->getAmount() / $money->getCurrency()->getSubUnit(), $money->getCurrency()->getCurrencyCode()); } }
/** * @param Money $a * @param Money $b * @throws CurrencyMismatchException */ private function assertSameCurrency(Money $a, Money $b) { if ($a->getCurrency() != $b->getCurrency()) { throw new CurrencyMismatchException(); } }