You are here

protected function Price::assertSameCurrency in Price 8

Same name and namespace in other branches
  1. 3.x src/Price.php \Drupal\price\Price::assertSameCurrency()
  2. 2.0.x src/Price.php \Drupal\price\Price::assertSameCurrency()
  3. 2.x src/Price.php \Drupal\price\Price::assertSameCurrency()
  4. 3.0.x src/Price.php \Drupal\price\Price::assertSameCurrency()

Asserts that the two prices have the same currency.

Parameters

\Drupal\price\Price $first_price: The first price.

\Drupal\price\Price $second_price: The second price.

Throws

\Drupal\price\Exception\CurrencyMismatchException Thrown when the prices do not have the same currency.

3 calls to Price::assertSameCurrency()
Price::add in src/Price.php
Adds the given price to the current price.
Price::compareTo in src/Price.php
Compares the current price with the given price.
Price::subtract in src/Price.php
Subtracts the given price from the current price.

File

src/Price.php, line 279

Class

Price
Provides a value object for monetary values.

Namespace

Drupal\price

Code

protected function assertSameCurrency(Price $first_price, Price $second_price) {
  if ($first_price
    ->getCurrencyCode() != $second_price
    ->getCurrencyCode()) {
    throw new CurrencyMismatchException();
  }
}