diff --git a/src/Context/CashContext.php b/src/Context/CashContext.php index eb953e5..f8d6e46 100644 --- a/src/Context/CashContext.php +++ b/src/Context/CashContext.php @@ -21,7 +21,7 @@ final class CashContext implements Context * * For example, step 5 on CHF would allow CHF 0.00, CHF 0.05, CHF 0.10, etc. */ - private int $step; + private readonly int $step; /** * @param int $step The cash rounding step, in minor units. Must be a multiple of 2 and/or 5. diff --git a/src/Context/CustomContext.php b/src/Context/CustomContext.php index 9af9cd9..b7f545d 100644 --- a/src/Context/CustomContext.php +++ b/src/Context/CustomContext.php @@ -18,14 +18,14 @@ final class CustomContext implements Context /** * The scale of the monies using this context. */ - private int $scale; + private readonly int $scale; /** * An optional cash rounding step. Must be a multiple of 2 and/or 5. * * For example, scale=4 and step=5 would allow amounts of 0.0000, 0.0005, 0.0010, etc. */ - private int $step; + private readonly int $step; /** * @param int $scale The scale of the monies using this context. diff --git a/src/Currency.php b/src/Currency.php index 18d99f9..c8c6b1d 100644 --- a/src/Currency.php +++ b/src/Currency.php @@ -20,7 +20,7 @@ final class Currency implements Stringable, JsonSerializable * For non ISO currencies no constraints are defined, but the code must be unique across an application, and must * not conflict with ISO currency codes. */ - private string $currencyCode; + private readonly string $currencyCode; /** * The numeric currency code. @@ -33,7 +33,7 @@ final class Currency implements Stringable, JsonSerializable * * The numeric code can be useful when storing monies in a database. */ - private int $numericCode; + private readonly int $numericCode; /** * The name of the currency. @@ -41,7 +41,7 @@ final class Currency implements Stringable, JsonSerializable * For ISO currencies this will be the official English name of the currency. * For non ISO currencies no constraints are defined. */ - private string $name; + private readonly string $name; /** * The default number of fraction digits (typical scale) used with this currency. @@ -49,7 +49,7 @@ final class Currency implements Stringable, JsonSerializable * For example, the default number of fraction digits for the Euro is 2, while for the Japanese Yen it is 0. * This cannot be a negative number. */ - private int $defaultFractionDigits; + private readonly int $defaultFractionDigits; /** * Class constructor. diff --git a/src/CurrencyConverter.php b/src/CurrencyConverter.php index 67be717..d02c989 100644 --- a/src/CurrencyConverter.php +++ b/src/CurrencyConverter.php @@ -19,7 +19,7 @@ final class CurrencyConverter /** * The exchange rate provider. */ - private ExchangeRateProvider $exchangeRateProvider; + private readonly ExchangeRateProvider $exchangeRateProvider; /** * @param ExchangeRateProvider $exchangeRateProvider The exchange rate provider. diff --git a/src/Exception/CurrencyConversionException.php b/src/Exception/CurrencyConversionException.php index e9e0cf2..45ad2dc 100644 --- a/src/Exception/CurrencyConversionException.php +++ b/src/Exception/CurrencyConversionException.php @@ -9,9 +9,9 @@ */ class CurrencyConversionException extends MoneyException { - private string $sourceCurrencyCode; + private readonly string $sourceCurrencyCode; - private string $targetCurrencyCode; + private readonly string $targetCurrencyCode; /** * CurrencyConversionException constructor. diff --git a/src/ExchangeRateProvider/BaseCurrencyProvider.php b/src/ExchangeRateProvider/BaseCurrencyProvider.php index 5ee7b84..0e6078e 100644 --- a/src/ExchangeRateProvider/BaseCurrencyProvider.php +++ b/src/ExchangeRateProvider/BaseCurrencyProvider.php @@ -23,12 +23,12 @@ final class BaseCurrencyProvider implements ExchangeRateProvider /** * The provider for rates relative to the base currency. */ - private ExchangeRateProvider $provider; + private readonly ExchangeRateProvider $provider; /** * The code of the currency all the exchanges rates are based on. */ - private string $baseCurrencyCode; + private readonly string $baseCurrencyCode; /** * @param ExchangeRateProvider $provider The provider for rates relative to the base currency. diff --git a/src/ExchangeRateProvider/CachedProvider.php b/src/ExchangeRateProvider/CachedProvider.php index 4bae7c9..a08d44d 100644 --- a/src/ExchangeRateProvider/CachedProvider.php +++ b/src/ExchangeRateProvider/CachedProvider.php @@ -15,7 +15,7 @@ final class CachedProvider implements ExchangeRateProvider /** * The underlying exchange rate provider. */ - private ExchangeRateProvider $provider; + private readonly ExchangeRateProvider $provider; /** * The cached exchange rates. diff --git a/src/ExchangeRateProvider/PDOProvider.php b/src/ExchangeRateProvider/PDOProvider.php index 544946a..007d521 100644 --- a/src/ExchangeRateProvider/PDOProvider.php +++ b/src/ExchangeRateProvider/PDOProvider.php @@ -16,17 +16,17 @@ final class PDOProvider implements ExchangeRateProvider /** * The SELECT statement. */ - private \PDOStatement $statement; + private readonly \PDOStatement $statement; /** * The source currency code if fixed, or null if dynamic. */ - private ?string $sourceCurrencyCode = null; + private readonly ?string $sourceCurrencyCode; /** * The target currency code if fixed, or null if dynamic. */ - private ?string $targetCurrencyCode = null; + private readonly ?string $targetCurrencyCode; /** * Extra parameters set dynamically to resolve the query placeholders. @@ -47,18 +47,24 @@ public function __construct(\PDO $pdo, PDOProviderConfiguration $configuration) $conditions[] = sprintf('(%s)', $configuration->whereConditions); } + $sourceCurrencyCode = null; + $targetCurrencyCode = null; + if ($configuration->sourceCurrencyCode !== null) { - $this->sourceCurrencyCode = $configuration->sourceCurrencyCode; + $sourceCurrencyCode = $configuration->sourceCurrencyCode; } elseif ($configuration->sourceCurrencyColumnName !== null) { $conditions[] = sprintf('%s = ?', $configuration->sourceCurrencyColumnName); } if ($configuration->targetCurrencyCode !== null) { - $this->targetCurrencyCode = $configuration->targetCurrencyCode; + $targetCurrencyCode = $configuration->targetCurrencyCode; } elseif ($configuration->targetCurrencyColumnName !== null) { $conditions[] = sprintf('%s = ?', $configuration->targetCurrencyColumnName); } + $this->sourceCurrencyCode = $sourceCurrencyCode; + $this->targetCurrencyCode = $targetCurrencyCode; + $conditions = implode(' AND ' , $conditions); $query = sprintf( diff --git a/src/ISOCurrencyProvider.php b/src/ISOCurrencyProvider.php index 4c43b63..c808f88 100644 --- a/src/ISOCurrencyProvider.php +++ b/src/ISOCurrencyProvider.php @@ -18,7 +18,7 @@ final class ISOCurrencyProvider * * @psalm-var array */ - private array $currencyData; + private readonly array $currencyData; /** * An associative array of currency numeric code to currency code. diff --git a/src/Money.php b/src/Money.php index 97b469f..23cc02c 100644 --- a/src/Money.php +++ b/src/Money.php @@ -36,17 +36,17 @@ final class Money extends AbstractMoney /** * The amount. */ - private BigDecimal $amount; + private readonly BigDecimal $amount; /** * The currency. */ - private Currency $currency; + private readonly Currency $currency; /** * The context that defines the capability of this Money. */ - private Context $context; + private readonly Context $context; /** * @param BigDecimal $amount diff --git a/src/MoneyComparator.php b/src/MoneyComparator.php index 9c6354d..6fbb0f9 100644 --- a/src/MoneyComparator.php +++ b/src/MoneyComparator.php @@ -21,7 +21,7 @@ final class MoneyComparator /** * The exchange rate provider. */ - private ExchangeRateProvider $exchangeRateProvider; + private readonly ExchangeRateProvider $exchangeRateProvider; /** * Class constructor. diff --git a/src/RationalMoney.php b/src/RationalMoney.php index fa98d39..5d7ef67 100644 --- a/src/RationalMoney.php +++ b/src/RationalMoney.php @@ -18,9 +18,9 @@ */ final class RationalMoney extends AbstractMoney { - private BigRational $amount; + private readonly BigRational $amount; - private Currency $currency; + private readonly Currency $currency; /** * Class constructor.