protected function Price::assertSameCurrency in Price 2.x
Same name and namespace in other branches
- 8 src/Price.php \Drupal\price\Price::assertSameCurrency()
- 3.x src/Price.php \Drupal\price\Price::assertSameCurrency()
- 2.0.x src/Price.php \Drupal\price\Price::assertSameCurrency()
- 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 314
Class
- Price
- Provides a value object for monetary values.
Namespace
Drupal\priceCode
protected function assertSameCurrency(Price $first_price, Price $second_price) {
if ($first_price
->getCurrencyCode() != $second_price
->getCurrencyCode()) {
throw new CurrencyMismatchException(sprintf('The provided prices have mismatched currencies: %s, %s.', $first_price
->__toString(), $second_price
->__toString()));
}
}