Skip to content

Commit c198081

Browse files
Merge pull request #785 from moneyphp/dev_dep
upgrade doctrine/coding-standard to version 12
2 parents dfdb760 + d112de8 commit c198081

28 files changed

+48
-153
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"ext-gmp": "*",
3434
"ext-intl": "*",
3535
"cache/taggable-cache": "^1.1.0",
36-
"doctrine/coding-standard": "^9.0",
36+
"doctrine/coding-standard": "^12.0",
3737
"doctrine/instantiator": "^1.5.0 || ^2.0",
3838
"florianv/exchanger": "^2.8.1",
3939
"florianv/swap": "^4.3.0",

phpcs.xml.dist

+7
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,12 @@
2828
<!-- language-level non-strict comparison is (consciously) used in the codebase for performance reasons -->
2929
<exclude name="SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedEqualOperator"/>
3030
<exclude name="SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedNotEqualOperator"/>
31+
32+
<!-- We do not want trailing commas -->
33+
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLineDocComment"/>
34+
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
35+
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInClosureUse"/>
36+
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
37+
<exclude name="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
3138
</rule>
3239
</ruleset>

src/Converter.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@
1313
*/
1414
final class Converter
1515
{
16-
private Currencies $currencies;
17-
18-
private Exchange $exchange;
19-
20-
public function __construct(Currencies $currencies, Exchange $exchange)
16+
public function __construct(private readonly Currencies $currencies, private readonly Exchange $exchange)
2117
{
22-
$this->currencies = $currencies;
23-
$this->exchange = $exchange;
2418
}
2519

2620
public function convert(Money $money, Currency $counterCurrency, int $roundingMode = Money::ROUND_HALF_UP): Money

src/Currencies/AggregateCurrencies.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@
1515
*/
1616
final class AggregateCurrencies implements Currencies
1717
{
18-
/** @var Currencies[] */
19-
private array $currencies;
20-
2118
/**
2219
* @param Currencies[] $currencies
2320
*/
24-
public function __construct(array $currencies)
21+
public function __construct(private readonly array $currencies)
2522
{
26-
$this->currencies = $currencies;
2723
}
2824

2925
public function contains(Currency $currency): bool

src/Currencies/CachedCurrencies.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@
1919
*/
2020
final class CachedCurrencies implements Currencies
2121
{
22-
private Currencies $currencies;
23-
24-
private CacheItemPoolInterface $pool;
25-
26-
public function __construct(Currencies $currencies, CacheItemPoolInterface $pool)
22+
public function __construct(private readonly Currencies $currencies, private readonly CacheItemPoolInterface $pool)
2723
{
28-
$this->currencies = $currencies;
29-
$this->pool = $pool;
3024
}
3125

3226
public function contains(Currency $currency): bool

src/Currencies/CryptoCurrencies.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class CryptoCurrencies implements Currencies
2828
* minorUnit: non-negative-int
2929
* }>|null
3030
*/
31-
private static ?array $currencies = null;
31+
private static array|null $currencies = null;
3232

3333
public function contains(Currency $currency): bool
3434
{

src/Currencies/ISOCurrencies.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class ISOCurrencies implements Currencies
3030
* numericCode: positive-int
3131
* }>|null
3232
*/
33-
private static ?array $currencies = null;
33+
private static array|null $currencies = null;
3434

3535
public function contains(Currency $currency): bool
3636
{

src/CurrencyPair.php

+7-20
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,14 @@
1919
*/
2020
final class CurrencyPair implements JsonSerializable
2121
{
22-
/**
23-
* Currency to convert from.
24-
*/
25-
private Currency $baseCurrency;
26-
27-
/**
28-
* Currency to convert to.
29-
*/
30-
private Currency $counterCurrency;
31-
32-
/** @psalm-var numeric-string */
33-
private string $conversionRatio;
34-
3522
/**
3623
* @psalm-param numeric-string $conversionRatio
3724
*/
38-
public function __construct(Currency $baseCurrency, Currency $counterCurrency, string $conversionRatio)
39-
{
40-
$this->counterCurrency = $counterCurrency;
41-
$this->baseCurrency = $baseCurrency;
42-
$this->conversionRatio = $conversionRatio;
25+
public function __construct(
26+
private readonly Currency $baseCurrency,
27+
private readonly Currency $counterCurrency,
28+
private readonly string $conversionRatio
29+
) {
4330
}
4431

4532
/**
@@ -95,7 +82,7 @@ public function getConversionRatio(): string
9582
}
9683

9784
/**
98-
* Checks if an other CurrencyPair has the same parameters as this.
85+
* Checks if another CurrencyPair has the same parameters as this.
9986
*/
10087
public function equals(CurrencyPair $other): bool
10188
{
@@ -105,7 +92,7 @@ public function equals(CurrencyPair $other): bool
10592
}
10693

10794
/**
108-
* {@inheritdoc}
95+
* {@inheritDoc}
10996
*
11097
* @psalm-return array{baseCurrency: Currency, counterCurrency: Currency, ratio: numeric-string}
11198
*/

src/Exchange/ExchangerExchange.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222
*/
2323
final class ExchangerExchange implements Exchange
2424
{
25-
private ExchangeRateProvider $exchanger;
26-
27-
public function __construct(ExchangeRateProvider $exchanger)
25+
public function __construct(private readonly ExchangeRateProvider $exchanger)
2826
{
29-
$this->exchanger = $exchanger;
3027
}
3128

3229
public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair

src/Exchange/FixedExchange.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@
1414
*/
1515
final class FixedExchange implements Exchange
1616
{
17-
/** @psalm-var array<non-empty-string, array<non-empty-string, numeric-string>> */
18-
private array $list;
19-
2017
/** @psalm-param array<non-empty-string, array<non-empty-string, numeric-string>> $list */
21-
public function __construct(array $list)
18+
public function __construct(private readonly array $list)
2219
{
23-
$this->list = $list;
2420
}
2521

2622
public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair

src/Exchange/IndirectExchange.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,8 @@
2020
*/
2121
final class IndirectExchange implements Exchange
2222
{
23-
private Currencies $currencies;
24-
25-
private Exchange $exchange;
26-
27-
public function __construct(Exchange $exchange, Currencies $currencies)
23+
public function __construct(private readonly Exchange $exchange, private readonly Currencies $currencies)
2824
{
29-
$this->exchange = $exchange;
30-
$this->currencies = $currencies;
3125
}
3226

3327
public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair
@@ -99,7 +93,7 @@ private function getConversions(Currency $baseCurrency, Currency $counterCurrenc
9993
$node->parent = $currentNode;
10094

10195
$frontier->enqueue($node);
102-
} catch (UnresolvableCurrencyPairException $exception) {
96+
} catch (UnresolvableCurrencyPairException) {
10397
// Not a neighbor. Move on.
10498
}
10599
}

src/Exchange/IndirectExchangeQueuedItem.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99
/** @internal for sole consumption by {@see IndirectExchange} */
1010
final class IndirectExchangeQueuedItem
1111
{
12-
public Currency $currency;
13-
public bool $discovered = false;
14-
public ?self $parent = null;
12+
public bool $discovered = false;
13+
public self|null $parent = null;
1514

16-
public function __construct(Currency $currency)
15+
public function __construct(public Currency $currency)
1716
{
18-
$this->currency = $currency;
1917
}
2018
}

src/Exchange/ReversedCurrenciesExchange.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717
*/
1818
final class ReversedCurrenciesExchange implements Exchange
1919
{
20-
private Exchange $exchange;
21-
22-
public function __construct(Exchange $exchange)
20+
public function __construct(private readonly Exchange $exchange)
2321
{
24-
$this->exchange = $exchange;
2522
}
2623

2724
public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair

src/Exchange/SwapExchange.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
*/
2121
final class SwapExchange implements Exchange
2222
{
23-
private Swap $swap;
24-
25-
public function __construct(Swap $swap)
23+
public function __construct(private readonly Swap $swap)
2624
{
27-
$this->swap = $swap;
2825
}
2926

3027
public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair

src/Formatter/BitcoinMoneyFormatter.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,8 @@
2121
*/
2222
final class BitcoinMoneyFormatter implements MoneyFormatter
2323
{
24-
private int $fractionDigits;
25-
26-
private Currencies $currencies;
27-
28-
public function __construct(int $fractionDigits, Currencies $currencies)
24+
public function __construct(private readonly int $fractionDigits, private readonly Currencies $currencies)
2925
{
30-
$this->fractionDigits = $fractionDigits;
31-
$this->currencies = $currencies;
3226
}
3327

3428
public function format(Money $money): string

src/Formatter/DecimalMoneyFormatter.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@
1818
*/
1919
final class DecimalMoneyFormatter implements MoneyFormatter
2020
{
21-
private Currencies $currencies;
22-
23-
public function __construct(Currencies $currencies)
21+
public function __construct(private readonly Currencies $currencies)
2422
{
25-
$this->currencies = $currencies;
2623
}
2724

2825
/** @psalm-return numeric-string */

src/Formatter/IntlLocalizedDecimalFormatter.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,8 @@
2020
*/
2121
final class IntlLocalizedDecimalFormatter implements MoneyFormatter
2222
{
23-
private NumberFormatter $formatter;
24-
25-
private Currencies $currencies;
26-
27-
public function __construct(NumberFormatter $formatter, Currencies $currencies)
23+
public function __construct(private readonly NumberFormatter $formatter, private readonly Currencies $currencies)
2824
{
29-
$this->formatter = $formatter;
30-
$this->currencies = $currencies;
3125
}
3226

3327
public function format(Money $money): string

src/Formatter/IntlMoneyFormatter.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@
1919
*/
2020
final class IntlMoneyFormatter implements MoneyFormatter
2121
{
22-
private NumberFormatter $formatter;
23-
24-
private Currencies $currencies;
25-
26-
public function __construct(NumberFormatter $formatter, Currencies $currencies)
22+
public function __construct(private readonly NumberFormatter $formatter, private readonly Currencies $currencies)
2723
{
28-
$this->formatter = $formatter;
29-
$this->currencies = $currencies;
3024
}
3125

3226
public function format(Money $money): string

src/Money.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ final class Money implements JsonSerializable
5959
*/
6060
private string $amount;
6161

62-
private Currency $currency;
63-
6462
/**
6563
* @var Calculator
6664
* @psalm-var class-string<Calculator>
@@ -73,10 +71,8 @@ final class Money implements JsonSerializable
7371
*
7472
* @throws InvalidArgumentException If amount is not integer(ish).
7573
*/
76-
public function __construct(int|string $amount, Currency $currency)
74+
public function __construct(int|string $amount, private readonly Currency $currency)
7775
{
78-
$this->currency = $currency;
79-
8076
if (filter_var($amount, FILTER_VALIDATE_INT) === false) {
8177
$numberFromString = Number::fromString((string) $amount);
8278
if (! $numberFromString->isInteger()) {
@@ -464,7 +460,7 @@ public function isNegative(): bool
464460
}
465461

466462
/**
467-
* {@inheritdoc}
463+
* {@inheritDoc}
468464
*
469465
* @psalm-return array{amount: string, currency: string}
470466
*/

src/Parser/AggregateMoneyParser.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,20 @@
1616
*/
1717
final class AggregateMoneyParser implements MoneyParser
1818
{
19-
/**
20-
* @var MoneyParser[]
21-
* @psalm-var non-empty-array<MoneyParser>
22-
*/
23-
private array $parsers;
24-
2519
/**
2620
* @param MoneyParser[] $parsers
2721
* @psalm-param non-empty-array<MoneyParser> $parsers
2822
*/
29-
public function __construct(array $parsers)
23+
public function __construct(private readonly array $parsers)
3024
{
31-
$this->parsers = $parsers;
3225
}
3326

3427
public function parse(string $money, Currency|null $fallbackCurrency = null): Money
3528
{
3629
foreach ($this->parsers as $parser) {
3730
try {
3831
return $parser->parse($money, $fallbackCurrency);
39-
} catch (Exception\ParserException $e) {
32+
} catch (Exception\ParserException) {
4033
}
4134
}
4235

src/Parser/BitcoinMoneyParser.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@
2323
*/
2424
final class BitcoinMoneyParser implements MoneyParser
2525
{
26-
private int $fractionDigits;
27-
28-
public function __construct(int $fractionDigits)
26+
public function __construct(private readonly int $fractionDigits)
2927
{
30-
$this->fractionDigits = $fractionDigits;
3128
}
3229

3330
public function parse(string $money, Currency|null $fallbackCurrency = null): Money

src/Parser/DecimalMoneyParser.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ final class DecimalMoneyParser implements MoneyParser
2626
{
2727
public const DECIMAL_PATTERN = '/^(?P<sign>-)?(?P<digits>\d+)?\.?(?P<fraction>\d+)?$/';
2828

29-
private Currencies $currencies;
30-
31-
public function __construct(Currencies $currencies)
29+
public function __construct(private readonly Currencies $currencies)
3230
{
33-
$this->currencies = $currencies;
3431
}
3532

3633
public function parse(string $money, Currency|null $fallbackCurrency = null): Money

src/Parser/IntlLocalizedDecimalParser.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,8 @@
2424
*/
2525
final class IntlLocalizedDecimalParser implements MoneyParser
2626
{
27-
private NumberFormatter $formatter;
28-
29-
private Currencies $currencies;
30-
31-
public function __construct(NumberFormatter $formatter, Currencies $currencies)
27+
public function __construct(private readonly NumberFormatter $formatter, private readonly Currencies $currencies)
3228
{
33-
$this->formatter = $formatter;
34-
$this->currencies = $currencies;
3529
}
3630

3731
public function parse(string $money, Currency|null $fallbackCurrency = null): Money

0 commit comments

Comments
 (0)