From 580c3f4ffe9608d2beb56d418c68b3b112420e76 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 10 Nov 2019 12:49:51 +0000 Subject: another bulk of composer updates (cherry picked from commit 6685381fd8db507493c3d7c1793f8c05c681bbce) --- vendor/commerceguys/intl/src/Currency/Currency.php | 133 ++++++++++----------- 1 file changed, 62 insertions(+), 71 deletions(-) (limited to 'vendor/commerceguys/intl/src/Currency/Currency.php') diff --git a/vendor/commerceguys/intl/src/Currency/Currency.php b/vendor/commerceguys/intl/src/Currency/Currency.php index 6f9256bf0..28329795c 100644 --- a/vendor/commerceguys/intl/src/Currency/Currency.php +++ b/vendor/commerceguys/intl/src/Currency/Currency.php @@ -2,7 +2,10 @@ namespace CommerceGuys\Intl\Currency; -class Currency implements CurrencyEntityInterface +/** + * Represents a currency. + */ +final class Currency { /** * The alphanumeric currency code. @@ -37,47 +40,67 @@ class Currency implements CurrencyEntityInterface * * @var int */ - protected $fractionDigits; + protected $fractionDigits = 2; /** - * The currency locale (i.e. "en_US"). - * - * The currency name and symbol are locale specific. + * The locale (i.e. "en_US"). * * @var string */ protected $locale; /** - * Returns the string representation of the currency. + * Creates a new Currency instance. * - * @return string + * @param array $definition The definition array. */ - public function __toString() + public function __construct(array $definition) { - return $this->getCurrencyCode(); + foreach (['currency_code', 'name', 'numeric_code', 'locale'] as $requiredProperty) { + if (empty($definition[$requiredProperty])) { + throw new \InvalidArgumentException(sprintf('Missing required property "%s".', $requiredProperty)); + } + } + if (!isset($definition['symbol'])) { + $definition['symbol'] = $definition['currency_code']; + } + + $this->currencyCode = $definition['currency_code']; + $this->name = $definition['name']; + $this->numericCode = $definition['numeric_code']; + $this->symbol = $definition['symbol']; + if (isset($definition['fraction_digits'])) { + $this->fractionDigits = $definition['fraction_digits']; + } + $this->locale = $definition['locale']; } /** - * {@inheritdoc} + * Gets the string representation of the currency. + * + * @return string */ - public function getCurrencyCode() + public function __toString() { return $this->currencyCode; } /** - * {@inheritdoc} + * Gets the alphabetic currency code. + * + * @return string */ - public function setCurrencyCode($currencyCode) + public function getCurrencyCode() { - $this->currencyCode = $currencyCode; - - return $this; + return $this->currencyCode; } /** - * {@inheritdoc} + * Gets the currency name. + * + * This value is locale specific. + * + * @return string */ public function getName() { @@ -85,17 +108,12 @@ class Currency implements CurrencyEntityInterface } /** - * {@inheritdoc} - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - - /** - * {@inheritdoc} + * Gets the numeric currency code. + * + * The numeric code has three digits, and the first one can be a zero, + * hence the need to pass it around as a string. + * + * @return string */ public function getNumericCode() { @@ -103,17 +121,11 @@ class Currency implements CurrencyEntityInterface } /** - * {@inheritdoc} - */ - public function setNumericCode($numericCode) - { - $this->numericCode = $numericCode; - - return $this; - } - - /** - * {@inheritdoc} + * Gets the currency symbol. + * + * This value is locale specific. + * + * @return string */ public function getSymbol() { @@ -121,17 +133,12 @@ class Currency implements CurrencyEntityInterface } /** - * {@inheritdoc} - */ - public function setSymbol($symbol) - { - $this->symbol = $symbol; - - return $this; - } - - /** - * {@inheritdoc} + * Gets the number of fraction digits. + * + * Used when rounding or formatting an amount for display. + * Actual storage precision can be greater. + * + * @return int */ public function getFractionDigits() { @@ -139,30 +146,14 @@ class Currency implements CurrencyEntityInterface } /** - * {@inheritdoc} - */ - public function setFractionDigits($fractionDigits) - { - $this->fractionDigits = $fractionDigits; - - return $this; - } - - /** - * {@inheritdoc} + * Gets the locale. + * + * The currency name and symbol are locale specific. + * + * @return string */ public function getLocale() { return $this->locale; } - - /** - * {@inheritdoc} - */ - public function setLocale($locale) - { - $this->locale = $locale; - - return $this; - } } -- cgit v1.2.3