diff --git a/composer.json b/composer.json
index 2d2679be..333be9ac 100644
--- a/composer.json
+++ b/composer.json
@@ -33,7 +33,7 @@
"ext-gmp": "*",
"ext-intl": "*",
"cache/taggable-cache": "^1.1.0",
- "doctrine/coding-standard": "^9.0",
+ "doctrine/coding-standard": "^12.0",
"doctrine/instantiator": "^1.5.0 || ^2.0",
"florianv/exchanger": "^2.8.1",
"florianv/swap": "^4.3.0",
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index f5bdc25e..88722922 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -28,5 +28,12 @@
+
+
+
+
+
+
+
diff --git a/src/Converter.php b/src/Converter.php
index b53b246a..85325f2b 100644
--- a/src/Converter.php
+++ b/src/Converter.php
@@ -13,14 +13,8 @@
*/
final class Converter
{
- private Currencies $currencies;
-
- private Exchange $exchange;
-
- public function __construct(Currencies $currencies, Exchange $exchange)
+ public function __construct(private readonly Currencies $currencies, private readonly Exchange $exchange)
{
- $this->currencies = $currencies;
- $this->exchange = $exchange;
}
public function convert(Money $money, Currency $counterCurrency, int $roundingMode = Money::ROUND_HALF_UP): Money
diff --git a/src/Currencies/AggregateCurrencies.php b/src/Currencies/AggregateCurrencies.php
index 62aab46c..9980c79e 100644
--- a/src/Currencies/AggregateCurrencies.php
+++ b/src/Currencies/AggregateCurrencies.php
@@ -15,15 +15,11 @@
*/
final class AggregateCurrencies implements Currencies
{
- /** @var Currencies[] */
- private array $currencies;
-
/**
* @param Currencies[] $currencies
*/
- public function __construct(array $currencies)
+ public function __construct(private readonly array $currencies)
{
- $this->currencies = $currencies;
}
public function contains(Currency $currency): bool
diff --git a/src/Currencies/CachedCurrencies.php b/src/Currencies/CachedCurrencies.php
index 81d99416..a0808c20 100644
--- a/src/Currencies/CachedCurrencies.php
+++ b/src/Currencies/CachedCurrencies.php
@@ -19,14 +19,8 @@
*/
final class CachedCurrencies implements Currencies
{
- private Currencies $currencies;
-
- private CacheItemPoolInterface $pool;
-
- public function __construct(Currencies $currencies, CacheItemPoolInterface $pool)
+ public function __construct(private readonly Currencies $currencies, private readonly CacheItemPoolInterface $pool)
{
- $this->currencies = $currencies;
- $this->pool = $pool;
}
public function contains(Currency $currency): bool
diff --git a/src/Currencies/CryptoCurrencies.php b/src/Currencies/CryptoCurrencies.php
index 98542cb6..878db984 100644
--- a/src/Currencies/CryptoCurrencies.php
+++ b/src/Currencies/CryptoCurrencies.php
@@ -28,7 +28,7 @@ final class CryptoCurrencies implements Currencies
* minorUnit: non-negative-int
* }>|null
*/
- private static ?array $currencies = null;
+ private static array|null $currencies = null;
public function contains(Currency $currency): bool
{
diff --git a/src/Currencies/ISOCurrencies.php b/src/Currencies/ISOCurrencies.php
index 486b06ab..9bf8d78e 100644
--- a/src/Currencies/ISOCurrencies.php
+++ b/src/Currencies/ISOCurrencies.php
@@ -30,7 +30,7 @@ final class ISOCurrencies implements Currencies
* numericCode: positive-int
* }>|null
*/
- private static ?array $currencies = null;
+ private static array|null $currencies = null;
public function contains(Currency $currency): bool
{
diff --git a/src/CurrencyPair.php b/src/CurrencyPair.php
index 56d6e1fa..66082a55 100644
--- a/src/CurrencyPair.php
+++ b/src/CurrencyPair.php
@@ -19,27 +19,14 @@
*/
final class CurrencyPair implements JsonSerializable
{
- /**
- * Currency to convert from.
- */
- private Currency $baseCurrency;
-
- /**
- * Currency to convert to.
- */
- private Currency $counterCurrency;
-
- /** @psalm-var numeric-string */
- private string $conversionRatio;
-
/**
* @psalm-param numeric-string $conversionRatio
*/
- public function __construct(Currency $baseCurrency, Currency $counterCurrency, string $conversionRatio)
- {
- $this->counterCurrency = $counterCurrency;
- $this->baseCurrency = $baseCurrency;
- $this->conversionRatio = $conversionRatio;
+ public function __construct(
+ private readonly Currency $baseCurrency,
+ private readonly Currency $counterCurrency,
+ private readonly string $conversionRatio
+ ) {
}
/**
@@ -95,7 +82,7 @@ public function getConversionRatio(): string
}
/**
- * Checks if an other CurrencyPair has the same parameters as this.
+ * Checks if another CurrencyPair has the same parameters as this.
*/
public function equals(CurrencyPair $other): bool
{
@@ -105,7 +92,7 @@ public function equals(CurrencyPair $other): bool
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*
* @psalm-return array{baseCurrency: Currency, counterCurrency: Currency, ratio: numeric-string}
*/
diff --git a/src/Exchange/ExchangerExchange.php b/src/Exchange/ExchangerExchange.php
index 9d91992c..d7804217 100644
--- a/src/Exchange/ExchangerExchange.php
+++ b/src/Exchange/ExchangerExchange.php
@@ -22,11 +22,8 @@
*/
final class ExchangerExchange implements Exchange
{
- private ExchangeRateProvider $exchanger;
-
- public function __construct(ExchangeRateProvider $exchanger)
+ public function __construct(private readonly ExchangeRateProvider $exchanger)
{
- $this->exchanger = $exchanger;
}
public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair
diff --git a/src/Exchange/FixedExchange.php b/src/Exchange/FixedExchange.php
index 204c5efb..93db920f 100644
--- a/src/Exchange/FixedExchange.php
+++ b/src/Exchange/FixedExchange.php
@@ -14,13 +14,9 @@
*/
final class FixedExchange implements Exchange
{
- /** @psalm-var array> */
- private array $list;
-
/** @psalm-param array> $list */
- public function __construct(array $list)
+ public function __construct(private readonly array $list)
{
- $this->list = $list;
}
public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair
diff --git a/src/Exchange/IndirectExchange.php b/src/Exchange/IndirectExchange.php
index d170dc97..4fe5240c 100644
--- a/src/Exchange/IndirectExchange.php
+++ b/src/Exchange/IndirectExchange.php
@@ -20,14 +20,8 @@
*/
final class IndirectExchange implements Exchange
{
- private Currencies $currencies;
-
- private Exchange $exchange;
-
- public function __construct(Exchange $exchange, Currencies $currencies)
+ public function __construct(private readonly Exchange $exchange, private readonly Currencies $currencies)
{
- $this->exchange = $exchange;
- $this->currencies = $currencies;
}
public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair
@@ -99,7 +93,7 @@ private function getConversions(Currency $baseCurrency, Currency $counterCurrenc
$node->parent = $currentNode;
$frontier->enqueue($node);
- } catch (UnresolvableCurrencyPairException $exception) {
+ } catch (UnresolvableCurrencyPairException) {
// Not a neighbor. Move on.
}
}
diff --git a/src/Exchange/IndirectExchangeQueuedItem.php b/src/Exchange/IndirectExchangeQueuedItem.php
index 7656c88e..f93e072c 100644
--- a/src/Exchange/IndirectExchangeQueuedItem.php
+++ b/src/Exchange/IndirectExchangeQueuedItem.php
@@ -9,12 +9,10 @@
/** @internal for sole consumption by {@see IndirectExchange} */
final class IndirectExchangeQueuedItem
{
- public Currency $currency;
- public bool $discovered = false;
- public ?self $parent = null;
+ public bool $discovered = false;
+ public self|null $parent = null;
- public function __construct(Currency $currency)
+ public function __construct(public Currency $currency)
{
- $this->currency = $currency;
}
}
diff --git a/src/Exchange/ReversedCurrenciesExchange.php b/src/Exchange/ReversedCurrenciesExchange.php
index 697b4ec2..62777d5d 100644
--- a/src/Exchange/ReversedCurrenciesExchange.php
+++ b/src/Exchange/ReversedCurrenciesExchange.php
@@ -17,11 +17,8 @@
*/
final class ReversedCurrenciesExchange implements Exchange
{
- private Exchange $exchange;
-
- public function __construct(Exchange $exchange)
+ public function __construct(private readonly Exchange $exchange)
{
- $this->exchange = $exchange;
}
public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair
diff --git a/src/Exchange/SwapExchange.php b/src/Exchange/SwapExchange.php
index 94017200..8a860226 100644
--- a/src/Exchange/SwapExchange.php
+++ b/src/Exchange/SwapExchange.php
@@ -20,11 +20,8 @@
*/
final class SwapExchange implements Exchange
{
- private Swap $swap;
-
- public function __construct(Swap $swap)
+ public function __construct(private readonly Swap $swap)
{
- $this->swap = $swap;
}
public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair
diff --git a/src/Formatter/BitcoinMoneyFormatter.php b/src/Formatter/BitcoinMoneyFormatter.php
index 7eca31c6..3b7e8d63 100644
--- a/src/Formatter/BitcoinMoneyFormatter.php
+++ b/src/Formatter/BitcoinMoneyFormatter.php
@@ -21,14 +21,8 @@
*/
final class BitcoinMoneyFormatter implements MoneyFormatter
{
- private int $fractionDigits;
-
- private Currencies $currencies;
-
- public function __construct(int $fractionDigits, Currencies $currencies)
+ public function __construct(private readonly int $fractionDigits, private readonly Currencies $currencies)
{
- $this->fractionDigits = $fractionDigits;
- $this->currencies = $currencies;
}
public function format(Money $money): string
diff --git a/src/Formatter/DecimalMoneyFormatter.php b/src/Formatter/DecimalMoneyFormatter.php
index 8aab1c4d..ce963949 100644
--- a/src/Formatter/DecimalMoneyFormatter.php
+++ b/src/Formatter/DecimalMoneyFormatter.php
@@ -18,11 +18,8 @@
*/
final class DecimalMoneyFormatter implements MoneyFormatter
{
- private Currencies $currencies;
-
- public function __construct(Currencies $currencies)
+ public function __construct(private readonly Currencies $currencies)
{
- $this->currencies = $currencies;
}
/** @psalm-return numeric-string */
diff --git a/src/Formatter/IntlLocalizedDecimalFormatter.php b/src/Formatter/IntlLocalizedDecimalFormatter.php
index 296df1b7..e2f4385c 100644
--- a/src/Formatter/IntlLocalizedDecimalFormatter.php
+++ b/src/Formatter/IntlLocalizedDecimalFormatter.php
@@ -20,14 +20,8 @@
*/
final class IntlLocalizedDecimalFormatter implements MoneyFormatter
{
- private NumberFormatter $formatter;
-
- private Currencies $currencies;
-
- public function __construct(NumberFormatter $formatter, Currencies $currencies)
+ public function __construct(private readonly NumberFormatter $formatter, private readonly Currencies $currencies)
{
- $this->formatter = $formatter;
- $this->currencies = $currencies;
}
public function format(Money $money): string
diff --git a/src/Formatter/IntlMoneyFormatter.php b/src/Formatter/IntlMoneyFormatter.php
index c5f83f31..43073fdc 100644
--- a/src/Formatter/IntlMoneyFormatter.php
+++ b/src/Formatter/IntlMoneyFormatter.php
@@ -19,14 +19,8 @@
*/
final class IntlMoneyFormatter implements MoneyFormatter
{
- private NumberFormatter $formatter;
-
- private Currencies $currencies;
-
- public function __construct(NumberFormatter $formatter, Currencies $currencies)
+ public function __construct(private readonly NumberFormatter $formatter, private readonly Currencies $currencies)
{
- $this->formatter = $formatter;
- $this->currencies = $currencies;
}
public function format(Money $money): string
diff --git a/src/Money.php b/src/Money.php
index a3654dc7..a1dff2d6 100644
--- a/src/Money.php
+++ b/src/Money.php
@@ -59,8 +59,6 @@ final class Money implements JsonSerializable
*/
private string $amount;
- private Currency $currency;
-
/**
* @var Calculator
* @psalm-var class-string
@@ -73,10 +71,8 @@ final class Money implements JsonSerializable
*
* @throws InvalidArgumentException If amount is not integer(ish).
*/
- public function __construct(int|string $amount, Currency $currency)
+ public function __construct(int|string $amount, private readonly Currency $currency)
{
- $this->currency = $currency;
-
if (filter_var($amount, FILTER_VALIDATE_INT) === false) {
$numberFromString = Number::fromString((string) $amount);
if (! $numberFromString->isInteger()) {
@@ -464,7 +460,7 @@ public function isNegative(): bool
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*
* @psalm-return array{amount: string, currency: string}
*/
diff --git a/src/Parser/AggregateMoneyParser.php b/src/Parser/AggregateMoneyParser.php
index dabd51d3..13e597e1 100644
--- a/src/Parser/AggregateMoneyParser.php
+++ b/src/Parser/AggregateMoneyParser.php
@@ -16,19 +16,12 @@
*/
final class AggregateMoneyParser implements MoneyParser
{
- /**
- * @var MoneyParser[]
- * @psalm-var non-empty-array
- */
- private array $parsers;
-
/**
* @param MoneyParser[] $parsers
* @psalm-param non-empty-array $parsers
*/
- public function __construct(array $parsers)
+ public function __construct(private readonly array $parsers)
{
- $this->parsers = $parsers;
}
public function parse(string $money, Currency|null $fallbackCurrency = null): Money
@@ -36,7 +29,7 @@ public function parse(string $money, Currency|null $fallbackCurrency = null): Mo
foreach ($this->parsers as $parser) {
try {
return $parser->parse($money, $fallbackCurrency);
- } catch (Exception\ParserException $e) {
+ } catch (Exception\ParserException) {
}
}
diff --git a/src/Parser/BitcoinMoneyParser.php b/src/Parser/BitcoinMoneyParser.php
index 6762fbee..b73bdab4 100644
--- a/src/Parser/BitcoinMoneyParser.php
+++ b/src/Parser/BitcoinMoneyParser.php
@@ -23,11 +23,8 @@
*/
final class BitcoinMoneyParser implements MoneyParser
{
- private int $fractionDigits;
-
- public function __construct(int $fractionDigits)
+ public function __construct(private readonly int $fractionDigits)
{
- $this->fractionDigits = $fractionDigits;
}
public function parse(string $money, Currency|null $fallbackCurrency = null): Money
diff --git a/src/Parser/DecimalMoneyParser.php b/src/Parser/DecimalMoneyParser.php
index 52a606a7..3e0e01cf 100644
--- a/src/Parser/DecimalMoneyParser.php
+++ b/src/Parser/DecimalMoneyParser.php
@@ -26,11 +26,8 @@ final class DecimalMoneyParser implements MoneyParser
{
public const DECIMAL_PATTERN = '/^(?P-)?(?P\d+)?\.?(?P\d+)?$/';
- private Currencies $currencies;
-
- public function __construct(Currencies $currencies)
+ public function __construct(private readonly Currencies $currencies)
{
- $this->currencies = $currencies;
}
public function parse(string $money, Currency|null $fallbackCurrency = null): Money
diff --git a/src/Parser/IntlLocalizedDecimalParser.php b/src/Parser/IntlLocalizedDecimalParser.php
index 36a424df..9fb28c7e 100644
--- a/src/Parser/IntlLocalizedDecimalParser.php
+++ b/src/Parser/IntlLocalizedDecimalParser.php
@@ -24,14 +24,8 @@
*/
final class IntlLocalizedDecimalParser implements MoneyParser
{
- private NumberFormatter $formatter;
-
- private Currencies $currencies;
-
- public function __construct(NumberFormatter $formatter, Currencies $currencies)
+ public function __construct(private readonly NumberFormatter $formatter, private readonly Currencies $currencies)
{
- $this->formatter = $formatter;
- $this->currencies = $currencies;
}
public function parse(string $money, Currency|null $fallbackCurrency = null): Money
diff --git a/src/Parser/IntlMoneyParser.php b/src/Parser/IntlMoneyParser.php
index 9e87c2e3..4371d3bd 100644
--- a/src/Parser/IntlMoneyParser.php
+++ b/src/Parser/IntlMoneyParser.php
@@ -25,14 +25,8 @@
*/
final class IntlMoneyParser implements MoneyParser
{
- private NumberFormatter $formatter;
-
- private Currencies $currencies;
-
- public function __construct(NumberFormatter $formatter, Currencies $currencies)
+ public function __construct(private readonly NumberFormatter $formatter, private readonly Currencies $currencies)
{
- $this->formatter = $formatter;
- $this->currencies = $currencies;
}
public function parse(string $money, Currency|null $fallbackCurrency = null): Money
diff --git a/src/Teller.php b/src/Teller.php
index 22121285..48e29413 100644
--- a/src/Teller.php
+++ b/src/Teller.php
@@ -43,24 +43,12 @@ public static function __callStatic(string $method, array $arguments): self
);
}
- private Currency $currency;
-
- private MoneyFormatter $formatter;
-
- private MoneyParser $parser;
-
- private int $roundingMode = Money::ROUND_HALF_UP;
-
public function __construct(
- Currency $currency,
- MoneyParser $parser,
- MoneyFormatter $formatter,
- int $roundingMode = Money::ROUND_HALF_UP
+ private readonly Currency $currency,
+ private readonly MoneyParser $parser,
+ private readonly MoneyFormatter $formatter,
+ private readonly int $roundingMode = Money::ROUND_HALF_UP
) {
- $this->currency = $currency;
- $this->parser = $parser;
- $this->formatter = $formatter;
- $this->roundingMode = $roundingMode;
}
/**
diff --git a/tests/Parser/DecimalMoneyParserTest.php b/tests/Parser/DecimalMoneyParserTest.php
index 25d30db0..a9b1cf4f 100644
--- a/tests/Parser/DecimalMoneyParserTest.php
+++ b/tests/Parser/DecimalMoneyParserTest.php
@@ -45,7 +45,7 @@ public function itThrowsAnExceptionUponInvalidInputs($input): void
$currencies = $this->createMock(Currencies::class);
$currencies->method('subunitFor')
- ->with(self::callback(static fn (Currency $givenCurrency): bool => 'USD' === $givenCurrency->getCode()))
+ ->with(self::callback(static fn (Currency $givenCurrency): bool => $givenCurrency->getCode() === 'USD'))
->willReturn(2);
$parser = new DecimalMoneyParser($currencies);
diff --git a/tests/Parser/IntlLocalizedDecimalParserTest.php b/tests/Parser/IntlLocalizedDecimalParserTest.php
index 168ffd32..7cd7ed23 100644
--- a/tests/Parser/IntlLocalizedDecimalParserTest.php
+++ b/tests/Parser/IntlLocalizedDecimalParserTest.php
@@ -30,7 +30,7 @@ public function itParsesMoney(string $string, int $units, string $locale): void
$currencies = $this->createMock(Currencies::class);
$currencies->method('subunitFor')
- ->with(self::callback(static fn (Currency $givenCurrency): bool => 'USD' === $givenCurrency->getCode()))
+ ->with(self::callback(static fn (Currency $givenCurrency): bool => $givenCurrency->getCode() === 'USD'))
->willReturn(2);
$currencyCode = 'USD';
diff --git a/tests/Parser/IntlMoneyParserTest.php b/tests/Parser/IntlMoneyParserTest.php
index 1f68901d..a87d85de 100644
--- a/tests/Parser/IntlMoneyParserTest.php
+++ b/tests/Parser/IntlMoneyParserTest.php
@@ -30,7 +30,7 @@ public function itParsesMoney(string $string, int $units): void
$currencies = $this->createMock(Currencies::class);
$currencies->method('subunitFor')
- ->with(self::callback(static fn (Currency $givenCurrency): bool => 'USD' === $givenCurrency->getCode()))
+ ->with(self::callback(static fn (Currency $givenCurrency): bool => $givenCurrency->getCode() === 'USD'))
->willReturn(2);
$currencyCode = 'USD';