コード例 #1
0
ファイル: money.php プロジェクト: rocketpastsix/OOPExample
 /**
  * @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());
 }
コード例 #2
0
ファイル: Money.php プロジェクト: barryvdh/money
 /**
  * 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);
 }
コード例 #3
0
ファイル: CurrencyPair.php プロジェクト: barryvdh/money
 /**
  * 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;
 }
コード例 #4
0
ファイル: Money.php プロジェクト: mihaeu/PW-SimpleShop
 private function ensureCurrenciesMatch(Currency $myCurrency, Currency $yourCurrency)
 {
     if (!$myCurrency->equals($yourCurrency)) {
         throw new \InvalidArgumentException('Currency mismatch');
     }
 }
コード例 #5
0
ファイル: CurrencyTest.php プロジェクト: mihaeu/PW-SimpleShop
 public function testCanCompareDifferentCurrencies()
 {
     $eur = new Currency('EUR');
     $this->assertFalse($eur->equals($this->createUsd()));
 }
コード例 #6
0
ファイル: Money.php プロジェクト: superbalist/php-money
 /**
  * @param Money $money
  * @return bool
  */
 public function isSameCurrencyAs(Money $money)
 {
     return $this->currency->equals($money->getCurrency());
 }