Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade doctrine/coding-standard to version 12 #785

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,12 @@
<!-- language-level non-strict comparison is (consciously) used in the codebase for performance reasons -->
<exclude name="SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedEqualOperator"/>
<exclude name="SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedNotEqualOperator"/>

<!-- We do not want trailing commas -->
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLineDocComment"/>
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInClosureUse"/>
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
<exclude name="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
</rule>
</ruleset>
8 changes: 1 addition & 7 deletions src/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions src/Currencies/AggregateCurrencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/Currencies/CachedCurrencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Currencies/CryptoCurrencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Currencies/ISOCurrencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
27 changes: 7 additions & 20 deletions src/CurrencyPair.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

/**
Expand Down Expand Up @@ -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
{
Expand All @@ -105,7 +92,7 @@ public function equals(CurrencyPair $other): bool
}

/**
* {@inheritdoc}
* {@inheritDoc}
*
* @psalm-return array{baseCurrency: Currency, counterCurrency: Currency, ratio: numeric-string}
*/
Expand Down
5 changes: 1 addition & 4 deletions src/Exchange/ExchangerExchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions src/Exchange/FixedExchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@
*/
final class FixedExchange implements Exchange
{
/** @psalm-var array<non-empty-string, array<non-empty-string, numeric-string>> */
private array $list;

/** @psalm-param array<non-empty-string, array<non-empty-string, numeric-string>> $list */
public function __construct(array $list)
public function __construct(private readonly array $list)
{
$this->list = $list;
}

public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair
Expand Down
10 changes: 2 additions & 8 deletions src/Exchange/IndirectExchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/Exchange/IndirectExchangeQueuedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 1 addition & 4 deletions src/Exchange/ReversedCurrenciesExchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Exchange/SwapExchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/Formatter/BitcoinMoneyFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Formatter/DecimalMoneyFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
8 changes: 1 addition & 7 deletions src/Formatter/IntlLocalizedDecimalFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/Formatter/IntlMoneyFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ final class Money implements JsonSerializable
*/
private string $amount;

private Currency $currency;

/**
* @var Calculator
* @psalm-var class-string<Calculator>
Expand All @@ -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()) {
Expand Down Expand Up @@ -464,7 +460,7 @@ public function isNegative(): bool
}

/**
* {@inheritdoc}
* {@inheritDoc}
*
* @psalm-return array{amount: string, currency: string}
*/
Expand Down
11 changes: 2 additions & 9 deletions src/Parser/AggregateMoneyParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,20 @@
*/
final class AggregateMoneyParser implements MoneyParser
{
/**
* @var MoneyParser[]
* @psalm-var non-empty-array<MoneyParser>
*/
private array $parsers;

/**
* @param MoneyParser[] $parsers
* @psalm-param non-empty-array<MoneyParser> $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
{
foreach ($this->parsers as $parser) {
try {
return $parser->parse($money, $fallbackCurrency);
} catch (Exception\ParserException $e) {
} catch (Exception\ParserException) {
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/Parser/BitcoinMoneyParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Parser/DecimalMoneyParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ final class DecimalMoneyParser implements MoneyParser
{
public const DECIMAL_PATTERN = '/^(?P<sign>-)?(?P<digits>\d+)?\.?(?P<fraction>\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
Expand Down
8 changes: 1 addition & 7 deletions src/Parser/IntlLocalizedDecimalParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading