/** * @param money $amount * @return money */ public function add(Money $amount) { if (!$this->currency->equals($amount->getCurrency())) { throw new \InvalidArgumentException('Currency mismatch'); } return new Money($this->currency, $this->amount + $amount->getValue()); }
/** * Checks whether a Money has the same Currency as this. * * @param Money $other * * @return bool */ public function isSameCurrency(Money $other) { return $this->currency->equals($other->currency); }
/** * Checks if an other CurrencyPair has the same parameters as this. * * @param CurrencyPair $other * * @return bool */ public function equals(CurrencyPair $other) { return $this->baseCurrency->equals($other->baseCurrency) && $this->counterCurrency->equals($other->counterCurrency) && $this->conversionRatio === $other->conversionRatio; }
private function ensureCurrenciesMatch(Currency $myCurrency, Currency $yourCurrency) { if (!$myCurrency->equals($yourCurrency)) { throw new \InvalidArgumentException('Currency mismatch'); } }
public function testCanCompareDifferentCurrencies() { $eur = new Currency('EUR'); $this->assertFalse($eur->equals($this->createUsd())); }
/** * @param Money $money * @return bool */ public function isSameCurrencyAs(Money $money) { return $this->currency->equals($money->getCurrency()); }