Example #1
0
 /**
  * @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());
 }
Example #2
0
 /**
  * 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);
 }
Example #3
0
 /**
  * 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;
 }
Example #4
0
 private function ensureCurrenciesMatch(Currency $myCurrency, Currency $yourCurrency)
 {
     if (!$myCurrency->equals($yourCurrency)) {
         throw new \InvalidArgumentException('Currency mismatch');
     }
 }
Example #5
0
 public function testCanCompareDifferentCurrencies()
 {
     $eur = new Currency('EUR');
     $this->assertFalse($eur->equals($this->createUsd()));
 }
Example #6
0
 /**
  * @param Money $money
  * @return bool
  */
 public function isSameCurrencyAs(Money $money)
 {
     return $this->currency->equals($money->getCurrency());
 }