From b80f8281ab84802fc9e53219b1f81bf204214f33 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Fri, 26 Jan 2024 13:29:15 +0100 Subject: [PATCH 1/4] feat: bump dev-dependencies --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 3e7e2755..c6098118 100644 --- a/composer.json +++ b/composer.json @@ -33,19 +33,19 @@ "ext-gmp": "*", "ext-intl": "*", "cache/taggable-cache": "^1.1.0", - "doctrine/coding-standard": "^9.0", - "doctrine/instantiator": "^1.4.0", - "florianv/exchanger": "^2.6.3", + "doctrine/coding-standard": "^12.0", + "doctrine/instantiator": "^1.5.0 || ^2.0", + "florianv/exchanger": "^2.8.1", "florianv/swap": "^4.3.0", - "moneyphp/iso-currencies": "^3.2.1", - "moneyphp/crypto-currencies": "^1.0.0", - "php-http/message": "^1.11.0", - "php-http/mock-client": "^1.4.1", + "moneyphp/iso-currencies": "^3.3 || ^4.0", + "moneyphp/crypto-currencies": "^1.1.0", + "php-http/message": "^1.16.0", + "php-http/mock-client": "^1.6.0", "phpbench/phpbench": "^1.2.5", "phpunit/phpunit": "^9.5.4", "psalm/plugin-phpunit": "^0.18.4", "psr/cache": "^1.0.1 || ^2.0 || ^3.0", - "vimeo/psalm": "~5.15.0" + "vimeo/psalm": "~5.20" }, "suggest": { "ext-gmp": "Calculate without integer limits", From f783796552b8fb3d27b55d0abca84b453e148c45 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Fri, 26 Jan 2024 13:34:04 +0100 Subject: [PATCH 2/4] feat: bump dev-dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c6098118..93a7abd0 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "phpunit/phpunit": "^9.5.4", "psalm/plugin-phpunit": "^0.18.4", "psr/cache": "^1.0.1 || ^2.0 || ^3.0", - "vimeo/psalm": "~5.20" + "vimeo/psalm": "~5.20.0" }, "suggest": { "ext-gmp": "Calculate without integer limits", From 4444201bfbfb80e64e5aca7a9ac83124fdc62208 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Fri, 26 Jan 2024 13:39:29 +0100 Subject: [PATCH 3/4] feat: fix phpcs warnings/errors --- src/Calculator/BcMathCalculator.php | 14 +-- src/Calculator/GmpCalculator.php | 20 +-- src/Converter.php | 18 +-- src/Currencies.php | 4 +- src/Currencies/AggregateCurrencies.php | 10 +- src/Currencies/CachedCurrencies.php | 10 +- src/Currencies/CryptoCurrencies.php | 10 +- src/Currencies/CurrencyList.php | 4 +- src/Currencies/ISOCurrencies.php | 10 +- src/CurrencyPair.php | 12 +- .../UnresolvableCurrencyPairException.php | 2 +- src/Exchange/ExchangerExchange.php | 7 +- src/Exchange/FixedExchange.php | 8 +- src/Exchange/IndirectExchange.php | 12 +- src/Exchange/IndirectExchangeQueuedItem.php | 8 +- src/Exchange/ReversedCurrenciesExchange.php | 7 +- src/Exchange/SwapExchange.php | 5 +- src/Formatter/BitcoinMoneyFormatter.php | 8 +- src/Formatter/DecimalMoneyFormatter.php | 5 +- .../IntlLocalizedDecimalFormatter.php | 8 +- src/Formatter/IntlMoneyFormatter.php | 8 +- src/Money.php | 10 +- src/Number.php | 6 +- src/PHPUnit/Comparator.php | 2 +- src/Parser/AggregateMoneyParser.php | 11 +- src/Parser/BitcoinMoneyParser.php | 5 +- src/Parser/DecimalMoneyParser.php | 5 +- src/Parser/IntlLocalizedDecimalParser.php | 8 +- src/Parser/IntlMoneyParser.php | 8 +- src/Teller.php | 82 ++++++------- static-analysis/money-is-pure.php | 6 +- tests/Calculator/BcMathCalculatorTest.php | 18 +-- tests/Calculator/CalculatorTestCase.php | 6 +- tests/Calculator/GmpCalculatorTest.php | 22 +--- tests/ComparatorTest.php | 16 +-- tests/ConverterTest.php | 20 ++- tests/Currencies/AggregateCurrenciesTest.php | 12 +- tests/Currencies/CachedCurrenciesTest.php | 10 +- tests/Currencies/CryptoCurrenciesTest.php | 12 +- tests/Currencies/CurrencyListTest.php | 8 +- tests/Currencies/ISOCurrenciesTest.php | 16 +-- tests/CurrencyPairTest.php | 26 ++-- tests/CurrencyTest.php | 16 +-- tests/Exchange/IndirectExchangeTest.php | 12 +- .../ReversedCurrenciesExchangeTest.php | 8 +- tests/Exchange/SwapExchangeTest.php | 2 +- .../Formatter/AggregateMoneyFormatterTest.php | 2 +- tests/Formatter/BitcoinMoneyFormatterTest.php | 2 +- tests/MoneyTest.php | 42 ++----- tests/NumberTest.php | 2 +- tests/Parser/AggregateMoneyParserTest.php | 4 +- tests/Parser/BitcoinMoneyParserTest.php | 4 +- tests/Parser/DecimalMoneyParserTest.php | 2 +- .../Parser/IntlLocalizedDecimalParserTest.php | 22 +--- tests/Parser/IntlMoneyParserTest.php | 18 +-- tests/TellerTest.php | 116 +++++------------- 56 files changed, 237 insertions(+), 514 deletions(-) diff --git a/src/Calculator/BcMathCalculator.php b/src/Calculator/BcMathCalculator.php index 123af44c..8cb61ca4 100644 --- a/src/Calculator/BcMathCalculator.php +++ b/src/Calculator/BcMathCalculator.php @@ -129,7 +129,7 @@ public static function round(string $number, int $roundingMode): string return bcadd( $number->__toString(), $number->getIntegerRoundingMultiplier(), - 0 + 0, ); } @@ -145,7 +145,7 @@ public static function round(string $number, int $roundingMode): string return bcadd( $number->__toString(), $number->getIntegerRoundingMultiplier(), - 0 + 0, ); } @@ -154,7 +154,7 @@ public static function round(string $number, int $roundingMode): string return bcadd( $number->__toString(), $number->getIntegerRoundingMultiplier(), - 0 + 0, ); } @@ -169,7 +169,7 @@ public static function round(string $number, int $roundingMode): string return bcadd( $number->__toString(), $number->getIntegerRoundingMultiplier(), - 0 + 0, ); } @@ -178,14 +178,14 @@ public static function round(string $number, int $roundingMode): string return bcadd( $number->__toString(), $number->getIntegerRoundingMultiplier(), - 0 + 0, ); } return bcadd( $number->__toString(), '0', - 0 + 0, ); } @@ -203,7 +203,7 @@ private static function roundDigit(Number $number): string return bcadd( $number->__toString(), $number->getIntegerRoundingMultiplier(), - 0 + 0, ); } diff --git a/src/Calculator/GmpCalculator.php b/src/Calculator/GmpCalculator.php index dd912126..bb4b3963 100644 --- a/src/Calculator/GmpCalculator.php +++ b/src/Calculator/GmpCalculator.php @@ -159,8 +159,8 @@ public static function divide(string $amount, string $divisor): string gmp_div_q( gmp_mul($remainder, gmp_init('1' . str_pad('', self::SCALE, '0'))), gmp_init((string) $divisor), - GMP_ROUND_MINUSINF - ) + GMP_ROUND_MINUSINF, + ), ); if ($divisionOfRemainder[0] === '-') { @@ -237,7 +237,7 @@ public static function round(string $number, int $roundingMode): string if ($roundingMode === Money::ROUND_HALF_UP) { return self::add( $number->getIntegerPart(), - $number->getIntegerRoundingMultiplier() + $number->getIntegerRoundingMultiplier(), ); } @@ -252,7 +252,7 @@ public static function round(string $number, int $roundingMode): string return self::add( $number->getIntegerPart(), - $number->getIntegerRoundingMultiplier() + $number->getIntegerRoundingMultiplier(), ); } @@ -260,7 +260,7 @@ public static function round(string $number, int $roundingMode): string if ($number->isCurrentEven()) { return self::add( $number->getIntegerPart(), - $number->getIntegerRoundingMultiplier() + $number->getIntegerRoundingMultiplier(), ); } @@ -271,13 +271,13 @@ public static function round(string $number, int $roundingMode): string if ($number->isNegative()) { return self::add( $number->getIntegerPart(), - '0' + '0', ); } return self::add( $number->getIntegerPart(), - $number->getIntegerRoundingMultiplier() + $number->getIntegerRoundingMultiplier(), ); } @@ -285,13 +285,13 @@ public static function round(string $number, int $roundingMode): string if ($number->isNegative()) { return self::add( $number->getIntegerPart(), - $number->getIntegerRoundingMultiplier() + $number->getIntegerRoundingMultiplier(), ); } return self::add( $number->getIntegerPart(), - '0' + '0', ); } @@ -308,7 +308,7 @@ private static function roundDigit(Number $number): string if ($number->isCloserToNext()) { return self::add( $number->getIntegerPart(), - $number->getIntegerRoundingMultiplier() + $number->getIntegerRoundingMultiplier(), ); } diff --git a/src/Converter.php b/src/Converter.php index b53b246a..91721b4f 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 Currencies $currencies, private Exchange $exchange) { - $this->currencies = $currencies; - $this->exchange = $exchange; } public function convert(Money $money, Currency $counterCurrency, int $roundingMode = Money::ROUND_HALF_UP): Money @@ -29,9 +23,9 @@ public function convert(Money $money, Currency $counterCurrency, int $roundingMo $money, $this->exchange->quote( $money->getCurrency(), - $counterCurrency + $counterCurrency, ), - $roundingMode + $roundingMode, ); } @@ -40,7 +34,7 @@ public function convertAndReturnWithCurrencyPair(Money $money, Currency $counter { $pair = $this->exchange->quote( $money->getCurrency(), - $counterCurrency + $counterCurrency, ); return [$this->convertAgainstCurrencyPair($money, $pair, $roundingMode), $pair]; @@ -53,8 +47,8 @@ public function convertAgainstCurrencyPair(Money $money, CurrencyPair $currencyP sprintf( 'Expecting to convert against base currency %s, but got %s instead', $money->getCurrency()->getCode(), - $currencyPair->getBaseCurrency()->getCode() - ) + $currencyPair->getBaseCurrency()->getCode(), + ), ); } diff --git a/src/Currencies.php b/src/Currencies.php index b9b70527..b1558072 100644 --- a/src/Currencies.php +++ b/src/Currencies.php @@ -25,8 +25,6 @@ public function contains(Currency $currency): bool; */ public function subunitFor(Currency $currency): int; - /** - * @psalm-return Traversable - */ + /** @psalm-return Traversable */ public function getIterator(): Traversable; } diff --git a/src/Currencies/AggregateCurrencies.php b/src/Currencies/AggregateCurrencies.php index 62aab46c..e4f6504d 100644 --- a/src/Currencies/AggregateCurrencies.php +++ b/src/Currencies/AggregateCurrencies.php @@ -15,15 +15,9 @@ */ final class AggregateCurrencies implements Currencies { - /** @var Currencies[] */ - private array $currencies; - - /** - * @param Currencies[] $currencies - */ - public function __construct(array $currencies) + /** @param Currencies[] $currencies */ + public function __construct(private 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..c3ec5bd7 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 Currencies $currencies, private CacheItemPoolInterface $pool) { - $this->currencies = $currencies; - $this->pool = $pool; } public function contains(Currency $currency): bool @@ -79,7 +73,7 @@ function (Currency $currency): bool { $this->pool->save($item); return true; - } + }, ); } } diff --git a/src/Currencies/CryptoCurrencies.php b/src/Currencies/CryptoCurrencies.php index e57911ed..4347c504 100644 --- a/src/Currencies/CryptoCurrencies.php +++ b/src/Currencies/CryptoCurrencies.php @@ -28,7 +28,7 @@ final class CryptoCurrencies implements Currencies * minorUnit: positive-int|0 * }>|null */ - private static ?array $currencies = null; + private static array|null $currencies = null; public function contains(Currency $currency): bool { @@ -44,9 +44,7 @@ public function subunitFor(Currency $currency): int return $this->getCurrencies()[$currency->getCode()]['minorUnit']; } - /** - * @psalm-return Traversable - */ + /** @psalm-return Traversable */ public function getIterator(): Traversable { return new ArrayIterator( @@ -54,8 +52,8 @@ public function getIterator(): Traversable static function ($code) { return new Currency($code); }, - array_keys($this->getCurrencies()) - ) + array_keys($this->getCurrencies()), + ), ); } diff --git a/src/Currencies/CurrencyList.php b/src/Currencies/CurrencyList.php index 8c2f37be..2e18588a 100644 --- a/src/Currencies/CurrencyList.php +++ b/src/Currencies/CurrencyList.php @@ -53,8 +53,8 @@ public function getIterator(): Traversable static function ($code) { return new Currency($code); }, - array_keys($this->currencies) - ) + array_keys($this->currencies), + ), ); } } diff --git a/src/Currencies/ISOCurrencies.php b/src/Currencies/ISOCurrencies.php index f2890b31..0a586cdd 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 { @@ -60,9 +60,7 @@ public function numericCodeFor(Currency $currency): int return $this->getCurrencies()[$currency->getCode()]['numericCode']; } - /** - * @psalm-return Traversable - */ + /** @psalm-return Traversable */ public function getIterator(): Traversable { return new ArrayIterator( @@ -70,8 +68,8 @@ public function getIterator(): Traversable static function ($code) { return new Currency($code); }, - array_keys($this->getCurrencies()) - ) + array_keys($this->getCurrencies()), + ), ); } diff --git a/src/CurrencyPair.php b/src/CurrencyPair.php index 56d6e1fa..31e2d0ea 100644 --- a/src/CurrencyPair.php +++ b/src/CurrencyPair.php @@ -29,17 +29,11 @@ final class CurrencyPair implements JsonSerializable */ private Currency $counterCurrency; - /** @psalm-var numeric-string */ - private string $conversionRatio; - - /** - * @psalm-param numeric-string $conversionRatio - */ - public function __construct(Currency $baseCurrency, Currency $counterCurrency, string $conversionRatio) + /** @psalm-param numeric-string $conversionRatio */ + public function __construct(Currency $baseCurrency, Currency $counterCurrency, private string $conversionRatio) { $this->counterCurrency = $counterCurrency; $this->baseCurrency = $baseCurrency; - $this->conversionRatio = $conversionRatio; } /** @@ -105,7 +99,7 @@ public function equals(CurrencyPair $other): bool } /** - * {@inheritdoc} + * {@inheritDoc} * * @psalm-return array{baseCurrency: Currency, counterCurrency: Currency, ratio: numeric-string} */ diff --git a/src/Exception/UnresolvableCurrencyPairException.php b/src/Exception/UnresolvableCurrencyPairException.php index 1a35efaf..5bd7976f 100644 --- a/src/Exception/UnresolvableCurrencyPairException.php +++ b/src/Exception/UnresolvableCurrencyPairException.php @@ -23,7 +23,7 @@ public static function createFromCurrencies(Currency $baseCurrency, Currency $co $message = sprintf( 'Cannot resolve a currency pair for currencies: %s/%s', $baseCurrency->getCode(), - $counterCurrency->getCode() + $counterCurrency->getCode(), ); return new self($message); diff --git a/src/Exchange/ExchangerExchange.php b/src/Exchange/ExchangerExchange.php index 9d91992c..500d9d27 100644 --- a/src/Exchange/ExchangerExchange.php +++ b/src/Exchange/ExchangerExchange.php @@ -22,18 +22,15 @@ */ final class ExchangerExchange implements Exchange { - private ExchangeRateProvider $exchanger; - - public function __construct(ExchangeRateProvider $exchanger) + public function __construct(private ExchangeRateProvider $exchanger) { - $this->exchanger = $exchanger; } public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair { try { $query = new ExchangeRateQuery( - new ExchangerCurrencyPair($baseCurrency->getCode(), $counterCurrency->getCode()) + new ExchangerCurrencyPair($baseCurrency->getCode(), $counterCurrency->getCode()), ); $rate = $this->exchanger->getExchangeRate($query); } catch (ExchangerException) { diff --git a/src/Exchange/FixedExchange.php b/src/Exchange/FixedExchange.php index 204c5efb..fa80a31d 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 array $list) { - $this->list = $list; } public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair @@ -29,7 +25,7 @@ public function quote(Currency $baseCurrency, Currency $counterCurrency): Curren return new CurrencyPair( $baseCurrency, $counterCurrency, - $this->list[$baseCurrency->getCode()][$counterCurrency->getCode()] + $this->list[$baseCurrency->getCode()][$counterCurrency->getCode()], ); } diff --git a/src/Exchange/IndirectExchange.php b/src/Exchange/IndirectExchange.php index d170dc97..a987711d 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 Exchange $exchange, private Currencies $currencies) { - $this->exchange = $exchange; - $this->currencies = $currencies; } public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair @@ -47,7 +41,7 @@ static function (string $carry, CurrencyPair $pair) { return $calculator::multiply($carry, $pair->getConversionRatio()); }, - '1.0' + '1.0', ); return new CurrencyPair($baseCurrency, $counterCurrency, $rate); @@ -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..a7d77cb4 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 Exchange $exchange) { - $this->exchange = $exchange; } public function quote(Currency $baseCurrency, Currency $counterCurrency): CurrencyPair @@ -37,7 +34,7 @@ public function quote(Currency $baseCurrency, Currency $counterCurrency): Curren return new CurrencyPair( $baseCurrency, $counterCurrency, - $calculator::divide('1', $currencyPair->getConversionRatio()) + $calculator::divide('1', $currencyPair->getConversionRatio()), ); } catch (UnresolvableCurrencyPairException) { throw $exception; diff --git a/src/Exchange/SwapExchange.php b/src/Exchange/SwapExchange.php index 94017200..d2f57f31 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 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..748f0d55 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 int $fractionDigits, private 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..8618ddc5 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 Currencies $currencies) { - $this->currencies = $currencies; } /** @psalm-return numeric-string */ diff --git a/src/Formatter/IntlLocalizedDecimalFormatter.php b/src/Formatter/IntlLocalizedDecimalFormatter.php index 296df1b7..a16bd935 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 NumberFormatter $formatter, private 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..6fdd832b 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 NumberFormatter $formatter, private 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 fbbf3957..6e751d5d 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 Currency $currency) { - $this->currency = $currency; - if (filter_var($amount, FILTER_VALIDATE_INT) === false) { $numberFromString = Number::fromString((string) $amount); if (! $numberFromString->isInteger()) { @@ -429,7 +425,7 @@ public function absolute(): Money { return new self( self::$calculator::absolute($this->amount), - $this->currency + $this->currency, ); } @@ -464,7 +460,7 @@ public function isNegative(): bool } /** - * {@inheritdoc} + * {@inheritDoc} * * @psalm-return array{amount: string, currency: string} */ diff --git a/src/Number.php b/src/Number.php index c34ce11a..6af81ca9 100644 --- a/src/Number.php +++ b/src/Number.php @@ -52,7 +52,7 @@ public static function fromString(string $number): self return new self( $portions[0], - rtrim($portions[1] ?? '', '0') + rtrim($portions[1] ?? '', '0'), ); } @@ -163,7 +163,7 @@ public function base10(int $number): self return new self( $sign . substr($integerPart, 0, $integers), - rtrim(str_pad('', $zeroPad, '0') . substr($integerPart, $integers) . $this->fractionalPart, '0') + rtrim(str_pad('', $zeroPad, '0') . substr($integerPart, $integers) . $this->fractionalPart, '0'), ); } @@ -174,7 +174,7 @@ public function base10(int $number): self return new self( $sign . ltrim($integerPart . substr($this->fractionalPart, 0, $lengthFractionalPart - $fractions) . str_pad('', $zeroPad, '0'), '0'), - substr($this->fractionalPart, $lengthFractionalPart - $fractions) + substr($this->fractionalPart, $lengthFractionalPart - $fractions), ); } diff --git a/src/PHPUnit/Comparator.php b/src/PHPUnit/Comparator.php index 28a5d4ea..29c984cf 100644 --- a/src/PHPUnit/Comparator.php +++ b/src/PHPUnit/Comparator.php @@ -54,7 +54,7 @@ public function assertEquals( $actual, $delta = 0.0, $canonicalize = false, - $ignoreCase = false + $ignoreCase = false, ): void { assert($expected instanceof Money); assert($actual instanceof Money); diff --git a/src/Parser/AggregateMoneyParser.php b/src/Parser/AggregateMoneyParser.php index dabd51d3..5abc4506 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 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..624cb0e0 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 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..9bd59653 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 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..57ac4b66 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 NumberFormatter $formatter, private 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..419525e8 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 NumberFormatter $formatter, private 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..9f6651f5 100644 --- a/src/Teller.php +++ b/src/Teller.php @@ -39,28 +39,16 @@ public static function __callStatic(string $method, array $arguments): self $currency, $parser, $formatter, - $roundingMode + $roundingMode, ); } - 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 Currency $currency, + private MoneyParser $parser, + private MoneyFormatter $formatter, + private int $roundingMode = Money::ROUND_HALF_UP, ) { - $this->currency = $currency; - $this->parser = $parser; - $this->formatter = $formatter; - $this->roundingMode = $roundingMode; } /** @@ -72,7 +60,7 @@ public function __construct( public function equals(mixed $amount, mixed $other): bool { return $this->convertToMoney($amount)->equals( - $this->convertToMoney($other) + $this->convertToMoney($other), ); } @@ -87,7 +75,7 @@ public function equals(mixed $amount, mixed $other): bool public function compare(mixed $amount, mixed $other): int { return $this->convertToMoney($amount)->compare( - $this->convertToMoney($other) + $this->convertToMoney($other), ); } @@ -100,7 +88,7 @@ public function compare(mixed $amount, mixed $other): int public function greaterThan(mixed $amount, mixed $other): bool { return $this->convertToMoney($amount)->greaterThan( - $this->convertToMoney($other) + $this->convertToMoney($other), ); } @@ -113,7 +101,7 @@ public function greaterThan(mixed $amount, mixed $other): bool public function greaterThanOrEqual(mixed $amount, mixed $other): bool { return $this->convertToMoney($amount)->greaterThanOrEqual( - $this->convertToMoney($other) + $this->convertToMoney($other), ); } @@ -126,7 +114,7 @@ public function greaterThanOrEqual(mixed $amount, mixed $other): bool public function lessThan(mixed $amount, mixed $other): bool { return $this->convertToMoney($amount)->lessThan( - $this->convertToMoney($other) + $this->convertToMoney($other), ); } @@ -139,7 +127,7 @@ public function lessThan(mixed $amount, mixed $other): bool public function lessThanOrEqual(mixed $amount, mixed $other): bool { return $this->convertToMoney($amount)->lessThanOrEqual( - $this->convertToMoney($other) + $this->convertToMoney($other), ); } @@ -157,8 +145,8 @@ public function add(mixed $amount, mixed $other, mixed ...$others): string return $this->convertToString( $this->convertToMoney($amount)->add( $this->convertToMoney($other), - ...$this->convertToMoneyArray($others) - ) + ...$this->convertToMoneyArray($others), + ), ); } @@ -174,8 +162,8 @@ public function subtract(mixed $amount, mixed $other, mixed ...$others): string return $this->convertToString( $this->convertToMoney($amount)->subtract( $this->convertToMoney($other), - ...$this->convertToMoneyArray($others) - ) + ...$this->convertToMoneyArray($others), + ), ); } @@ -192,8 +180,8 @@ public function multiply(mixed $amount, int|float|string $multiplier): string return $this->convertToString( $this->convertToMoney($amount)->multiply( (string) $multiplier, - $this->roundingMode - ) + $this->roundingMode, + ), ); } @@ -210,8 +198,8 @@ public function divide(mixed $amount, int|float|string $divisor): string return $this->convertToString( $this->convertToMoney($amount)->divide( (string) $divisor, - $this->roundingMode - ) + $this->roundingMode, + ), ); } @@ -227,8 +215,8 @@ public function mod(mixed $amount, int|float|string $divisor): string return $this->convertToString( $this->convertToMoney($amount)->mod( - $this->convertToMoney((string) $divisor) - ) + $this->convertToMoney((string) $divisor), + ), ); } @@ -243,7 +231,7 @@ public function mod(mixed $amount, int|float|string $divisor): string public function allocate(mixed $amount, array $ratios): array { return $this->convertToStringArray( - $this->convertToMoney($amount)->allocate($ratios) + $this->convertToMoney($amount)->allocate($ratios), ); } @@ -258,7 +246,7 @@ public function allocate(mixed $amount, array $ratios): array public function allocateTo(mixed $amount, int $n): array { return $this->convertToStringArray( - $this->convertToMoney($amount)->allocateTo($n) + $this->convertToMoney($amount)->allocateTo($n), ); } @@ -272,8 +260,8 @@ public function ratioOf(mixed $amount, mixed $other): string { return $this->convertToString( $this->convertToMoney($amount)->ratioOf( - $this->convertToMoney($other) - ) + $this->convertToMoney($other), + ), ); } @@ -285,7 +273,7 @@ public function ratioOf(mixed $amount, mixed $other): string public function absolute(mixed $amount): string { return $this->convertToString( - $this->convertToMoney($amount)->absolute() + $this->convertToMoney($amount)->absolute(), ); } @@ -298,7 +286,7 @@ public function absolute(mixed $amount): string public function negative(mixed $amount): string { return $this->convertToString( - $this->convertToMoney($amount)->negative() + $this->convertToMoney($amount)->negative(), ); } @@ -343,8 +331,8 @@ public function min(mixed $amount, mixed ...$amounts): string return $this->convertToString( Money::min( $this->convertToMoney($amount), - ...$this->convertToMoneyArray($amounts) - ) + ...$this->convertToMoneyArray($amounts), + ), ); } @@ -359,8 +347,8 @@ public function max(mixed $amount, mixed ...$amounts): string return $this->convertToString( Money::max( $this->convertToMoney($amount), - ...$this->convertToMoneyArray($amounts) - ) + ...$this->convertToMoneyArray($amounts), + ), ); } @@ -375,8 +363,8 @@ public function sum(mixed $amount, mixed ...$amounts): string return $this->convertToString( Money::sum( $this->convertToMoney($amount), - ...$this->convertToMoneyArray($amounts) - ) + ...$this->convertToMoneyArray($amounts), + ), ); } @@ -391,8 +379,8 @@ public function avg(mixed $amount, mixed ...$amounts): string return $this->convertToString( Money::avg( $this->convertToMoney($amount), - ...$this->convertToMoneyArray($amounts) - ) + ...$this->convertToMoneyArray($amounts), + ), ); } diff --git a/static-analysis/money-is-pure.php b/static-analysis/money-is-pure.php index 6c18aebe..d3e6a143 100644 --- a/static-analysis/money-is-pure.php +++ b/static-analysis/money-is-pure.php @@ -17,8 +17,8 @@ function consumeMoney(Money $money): Money Money::min( new Money(10000, new Currency('USD')), Money::sum(new Money(123, new Currency('USD')), $money) - ->subtract(new Money(456, new Currency('USD'))) - ) - ) + ->subtract(new Money(456, new Currency('USD'))), + ), + ), ); } diff --git a/tests/Calculator/BcMathCalculatorTest.php b/tests/Calculator/BcMathCalculatorTest.php index 9d4d0391..6280e00f 100644 --- a/tests/Calculator/BcMathCalculatorTest.php +++ b/tests/Calculator/BcMathCalculatorTest.php @@ -68,26 +68,20 @@ public function itSubtractsAValueFromAnotherWithScaleSet(int $value1, int $value self::assertEqualNumber($expected, $this->getCalculator()::subtract((string) $value1, (string) $value2)); } - /** - * @test - */ + /** @test */ public function itComparesNumbersCloseToZero(): void { self::assertEquals(1, $this->getCalculator()::compare('1', '0.0005')); self::assertEquals(1, $this->getCalculator()::compare('1', '0.000000000000000000000000005')); } - /** - * @test - */ + /** @test */ public function itUsesScaleForAdd(): void { self::assertEquals('0.00130154000000', $this->getCalculator()::add('0.00125148', '0.00005006')); } - /** - * @test - */ + /** @test */ public function itUsesScaleForSubtract(): void { self::assertEqualNumber('0.00120142', $this->getCalculator()::subtract('0.00125148', '0.00005006')); @@ -113,9 +107,7 @@ public function itRefusesToModuloByZeroWhenDivisorIsTooSmallToCompare(): void $calculator::mod('1', '0.0000000000000000000000000000000000000000001'); } - /** - * @psalm-return array> - */ + /** @psalm-return array> */ public function compareLessExamples(): array { return array_merge( @@ -123,7 +115,7 @@ public function compareLessExamples(): array [ // Slightly below PHP_INT_MIN on 64 bit systems (does not work with the PhpCalculator) ['-9223372036854775810', '-9223372036854775809', -1], - ] + ], ); } } diff --git a/tests/Calculator/CalculatorTestCase.php b/tests/Calculator/CalculatorTestCase.php index ac80e61d..74d6c90e 100644 --- a/tests/Calculator/CalculatorTestCase.php +++ b/tests/Calculator/CalculatorTestCase.php @@ -77,7 +77,7 @@ public function itDividesAValueByAnother(int|string $value1, int|float $value2, $resultNumericString = substr( $this->getCalculator()::divide((string) $value1, (string) $value2), 0, - 12 + 12, ); self::assertIsNumeric($expectedNumericString); @@ -405,9 +405,7 @@ public function shareExamples(): array ]; } - /** - * @psalm-return array> - */ + /** @psalm-return array> */ public function compareLessExamples(): array { return [ diff --git a/tests/Calculator/GmpCalculatorTest.php b/tests/Calculator/GmpCalculatorTest.php index a2388d76..31d8b5dd 100644 --- a/tests/Calculator/GmpCalculatorTest.php +++ b/tests/Calculator/GmpCalculatorTest.php @@ -23,41 +23,31 @@ protected function getCalculator(): string return GmpCalculator::class; } - /** - * @test - */ + /** @test */ public function itMultipliesZero(): void { self::assertSame('0', $this->getCalculator()::multiply('0', '0.8')); } - /** - * @test - */ + /** @test */ public function itFloorsZero(): void { self::assertSame('0', $this->getCalculator()::floor('0')); } - /** - * @test - */ + /** @test */ public function itComparesZeroWithFraction(): void { self::assertSame(1, $this->getCalculator()::compare('0.5', '0')); } - /** - * @test - */ + /** @test */ public function it_divides_bug538(): void { self::assertSame('-4.54545454545455', $this->getCalculator()::divide('-500', '110')); } - /** - * @psalm-return array> - */ + /** @psalm-return array> */ public function compareLessExamples(): array { return array_merge( @@ -65,7 +55,7 @@ public function compareLessExamples(): array [ // Slightly below PHP_INT_MIN on 64 bit systems (does not work with the PhpCalculator) ['-9223372036854775810', '-9223372036854775809', -1], - ] + ], ); } } diff --git a/tests/ComparatorTest.php b/tests/ComparatorTest.php index bd7d48d9..8f2b56d2 100644 --- a/tests/ComparatorTest.php +++ b/tests/ComparatorTest.php @@ -19,9 +19,7 @@ protected function setUp(): void $this->comparator = new Comparator(); } - /** - * @test - */ + /** @test */ public function itAcceptsOnlyMoney(): void { $money_a = Money::EUR(1); @@ -32,9 +30,7 @@ public function itAcceptsOnlyMoney(): void self::assertTrue($this->comparator->accepts($money_a, $money_b)); } - /** - * @test - */ + /** @test */ public function itComparesUnequalValues(): void { $money_a = Money::EUR(1); @@ -50,7 +46,7 @@ public function itComparesUnequalValues(): void @@ @@ -€0.01 +$0.01', - $e->getDiff() + $e->getDiff(), ); return; @@ -59,9 +55,7 @@ public function itComparesUnequalValues(): void self::fail('ComparisonFailure should have been thrown.'); } - /** - * @test - */ + /** @test */ public function itComparesEqualValues(): void { $money_a = Money::EUR(1); @@ -72,7 +66,7 @@ public function itComparesEqualValues(): void self::assertEquals( $money_a, $money_b, - 'This is only here to increment the assertion counter, since we are testing an assertion' + 'This is only here to increment the assertion counter, since we are testing an assertion', ); } } diff --git a/tests/ConverterTest.php b/tests/ConverterTest.php index c853d0e7..b5ef455e 100644 --- a/tests/ConverterTest.php +++ b/tests/ConverterTest.php @@ -39,7 +39,7 @@ public function itConvertsToADifferentCurrency( int $subunitCounter, int|float $ratio, int|string $amount, - int $expectedAmount + int $expectedAmount, ): void { $baseCurrency = new Currency($baseCurrencyCode); $counterCurrency = new Currency($counterCurrencyCode); @@ -64,7 +64,7 @@ public function itConvertsToADifferentCurrency( $money = $converter->convert( new Money($amount, new Currency($baseCurrencyCode)), - $counterCurrency + $counterCurrency, ); self::assertEquals($expectedAmount, $money->getAmount()); @@ -90,7 +90,7 @@ public function itConvertsAndReturnWithCurrencyPair( int $subunitCounter, int|float $ratio, int|string $amount, - int $expectedAmount + int $expectedAmount, ): void { $baseCurrency = new Currency($baseCurrencyCode); $counterCurrency = new Currency($counterCurrencyCode); @@ -115,7 +115,7 @@ public function itConvertsAndReturnWithCurrencyPair( [$money, $currencyPair] = $converter->convertAndReturnWithCurrencyPair( new Money($amount, new Currency($baseCurrencyCode)), - $counterCurrency + $counterCurrency, ); self::assertEquals($expectedAmount, $money->getAmount()); @@ -143,7 +143,7 @@ public function itConvertsAgainstCurrencyPair( int $subunitCounter, int|float $ratio, int|string $amount, - int $expectedAmount + int $expectedAmount, ): void { $baseCurrency = new Currency($baseCurrencyCode); $counterCurrency = new Currency($counterCurrencyCode); @@ -164,7 +164,7 @@ public function itConvertsAgainstCurrencyPair( $money = $converter->convertAgainstCurrencyPair( new Money($amount, new Currency($baseCurrencyCode)), - $pair + $pair, ); self::assertEquals($expectedAmount, $money->getAmount()); @@ -190,7 +190,7 @@ public function itConvertsToADifferentCurrencyWhenDecimalSeparatorIsComma( $subunitCounter, $ratio, $amount, - $expectedAmount + $expectedAmount, ): void { $this->setLocale(LC_ALL, 'ru_RU.UTF-8'); @@ -201,13 +201,11 @@ public function itConvertsToADifferentCurrencyWhenDecimalSeparatorIsComma( $subunitCounter, $ratio, $amount, - $expectedAmount + $expectedAmount, ); } - /** - * @test - */ + /** @test */ public function itThrowsWhenConvertingAgainstTheWrongBaseCurrency(): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Currencies/AggregateCurrenciesTest.php b/tests/Currencies/AggregateCurrenciesTest.php index 4ebe1a2c..fb36619d 100644 --- a/tests/Currencies/AggregateCurrenciesTest.php +++ b/tests/Currencies/AggregateCurrenciesTest.php @@ -32,7 +32,7 @@ public function it_contains_currencies(): void self::assertTrue( (new AggregateCurrencies([$currencies, $otherCurrencies])) - ->contains($currency) + ->contains($currency), ); } @@ -52,7 +52,7 @@ public function it_might_not_contain_currencies(): void self::assertFalse( (new AggregateCurrencies([$currencies, $otherCurrencies])) - ->contains($currency) + ->contains($currency), ); } @@ -78,7 +78,7 @@ public function it_provides_subunit(): void self::assertSame( 2, (new AggregateCurrencies([$currencies, $otherCurrencies])) - ->subunitFor($currency) + ->subunitFor($currency), ); } @@ -122,7 +122,7 @@ public function it_is_iterable(): void new Currency('EUR'), new Currency('USD'), ], - iterator_to_array(new AggregateCurrencies([$currencies, $otherCurrencies]), false) + iterator_to_array(new AggregateCurrencies([$currencies, $otherCurrencies]), false), ); } @@ -146,12 +146,12 @@ public function it_can_operate_be_rewinded_and_reused(): void self::assertEquals( $expectedCurrencies, - iterator_to_array($iterator, false) + iterator_to_array($iterator, false), ); self::assertEquals( $expectedCurrencies, iterator_to_array($iterator, false), - 'Can re-use the previous iteration' + 'Can re-use the previous iteration', ); } } diff --git a/tests/Currencies/CachedCurrenciesTest.php b/tests/Currencies/CachedCurrenciesTest.php index 0993e817..28a7828b 100644 --- a/tests/Currencies/CachedCurrenciesTest.php +++ b/tests/Currencies/CachedCurrenciesTest.php @@ -47,7 +47,7 @@ public function it_checks_currencies_using_the_delegated_ones(): void self::assertTrue( (new CachedCurrencies($wrappedCurrencies, $cache)) - ->contains($currency) + ->contains($currency), ); } @@ -78,7 +78,7 @@ public function it_checks_currencies_from_the_cache(): void self::assertTrue( (new CachedCurrencies($wrappedCurrencies, $cache)) - ->contains($currency) + ->contains($currency), ); } @@ -119,7 +119,7 @@ public function it_is_iterable(): void new Currency('EUR'), new Currency('USD'), ], - iterator_to_array(new CachedCurrencies($wrappedCurrencies, $cache)) + iterator_to_array(new CachedCurrencies($wrappedCurrencies, $cache)), ); } @@ -151,7 +151,7 @@ public function it_checks_subunits_from_the_cache(): void self::assertEquals( 2, (new CachedCurrencies($wrappedCurrencies, $cache)) - ->subunitFor($currency) + ->subunitFor($currency), ); } @@ -186,7 +186,7 @@ public function it_saves_subunits_to_the_cache(): void self::assertEquals( 2, (new CachedCurrencies($wrappedCurrencies, $cache)) - ->subunitFor($currency) + ->subunitFor($currency), ); } } diff --git a/tests/Currencies/CryptoCurrenciesTest.php b/tests/Currencies/CryptoCurrenciesTest.php index dabf8e7e..31d60e7d 100644 --- a/tests/Currencies/CryptoCurrenciesTest.php +++ b/tests/Currencies/CryptoCurrenciesTest.php @@ -41,9 +41,7 @@ public function itProvidesSubunit(string $currency): void self::assertIsInt($currencies->subunitFor(new Currency($currency))); } - /** - * @test - */ + /** @test */ public function itThrowsAnExceptionWhenProvidingSubunitAndCurrencyIsUnknown(): void { $this->expectException(UnknownCurrencyException::class); @@ -53,9 +51,7 @@ public function itThrowsAnExceptionWhenProvidingSubunitAndCurrencyIsUnknown(): v $currencies->subunitFor(new Currency('XXXXXX')); } - /** - * @test - */ + /** @test */ public function itIsIterable(): void { $currencies = new CryptoCurrencies(); @@ -65,9 +61,7 @@ public function itIsIterable(): void self::assertContainsOnlyInstancesOf(Currency::class, $iterator); } - /** - * @psalm-return non-empty-list - */ + /** @psalm-return non-empty-list */ public function currencyCodeExamples(): array { /** @psalm-var non-empty-array $currencies */ diff --git a/tests/Currencies/CurrencyListTest.php b/tests/Currencies/CurrencyListTest.php index 1d6e073a..bbdf9484 100644 --- a/tests/Currencies/CurrencyListTest.php +++ b/tests/Currencies/CurrencyListTest.php @@ -47,9 +47,7 @@ public function itProvidesSubunit(string $currency): void self::assertIsInt($currencies->subunitFor(new Currency($currency))); } - /** - * @test - */ + /** @test */ public function itThrowsAnExceptionWhenProvidingSubunitAndCurrencyIsUnknown(): void { $currencies = new CurrencyList(self::CORRECT_CURRENCIES); @@ -59,9 +57,7 @@ public function itThrowsAnExceptionWhenProvidingSubunitAndCurrencyIsUnknown(): v $currencies->subunitFor(new Currency('XXXXXX')); } - /** - * @test - */ + /** @test */ public function itIsIterable(): void { $currencies = new CurrencyList(self::CORRECT_CURRENCIES); diff --git a/tests/Currencies/ISOCurrenciesTest.php b/tests/Currencies/ISOCurrenciesTest.php index 856862b2..ee546a90 100644 --- a/tests/Currencies/ISOCurrenciesTest.php +++ b/tests/Currencies/ISOCurrenciesTest.php @@ -41,9 +41,7 @@ public function itProvidesSubunit(string $currency): void self::assertIsInt($currencies->subunitFor(new Currency($currency))); } - /** - * @test - */ + /** @test */ public function itThrowsAnExceptionWhenProvidingSubunitAndCurrencyIsUnknown(): void { $this->expectException(UnknownCurrencyException::class); @@ -66,9 +64,7 @@ public function itProvidesNumericCode(string $currency): void self::assertIsInt($currencies->numericCodeFor(new Currency($currency))); } - /** - * @test - */ + /** @test */ public function itThrowsAnExceptionWhenProvidingNumericCodeAndCurrencyIsUnknown(): void { $this->expectException(UnknownCurrencyException::class); @@ -78,9 +74,7 @@ public function itThrowsAnExceptionWhenProvidingNumericCodeAndCurrencyIsUnknown( $currencies->numericCodeFor(new Currency('XXXXXX')); } - /** - * @test - */ + /** @test */ public function itIsIterable(): void { $currencies = new ISOCurrencies(); @@ -90,9 +84,7 @@ public function itIsIterable(): void self::assertContainsOnlyInstancesOf(Currency::class, $iterator); } - /** - * @psalm-return non-empty-list - */ + /** @psalm-return non-empty-list */ public function currencyCodeExamples(): array { /** @psalm-var non-empty-array $currencies */ diff --git a/tests/CurrencyPairTest.php b/tests/CurrencyPairTest.php index 7ccdfebe..f9414be5 100644 --- a/tests/CurrencyPairTest.php +++ b/tests/CurrencyPairTest.php @@ -13,15 +13,13 @@ /** @covers \Money\CurrencyPair */ final class CurrencyPairTest extends TestCase { - /** - * @test - */ + /** @test */ public function itProvidesGetters(): void { $pair = new CurrencyPair( new Currency('USD'), new Currency('EUR'), - '1.0' + '1.0', ); self::assertEquals('USD', $pair->getBaseCurrency()->getCode()); @@ -29,46 +27,40 @@ public function itProvidesGetters(): void self::assertEquals('1.0', $pair->getConversionRatio()); } - /** - * @test - */ + /** @test */ public function itProvidesEquality(): void { $pair1 = new CurrencyPair( new Currency('USD'), new Currency('EUR'), - '1.0' + '1.0', ); self::assertTrue($pair1->equals(new CurrencyPair( new Currency('USD'), new Currency('EUR'), - '1.0' + '1.0', ))); self::assertFalse($pair1->equals(new CurrencyPair( new Currency('USD'), new Currency('EUR'), - '2.0' + '2.0', ))); } - /** - * @test - */ + /** @test */ public function itConvertsToJson(): void { $pair = new CurrencyPair( new Currency('USD'), new Currency('EUR'), - '1.0' + '1.0', ); self::assertEquals('{"baseCurrency":"USD","counterCurrency":"EUR","ratio":"1.0"}', json_encode($pair)); } - /** - * @test - */ + /** @test */ public function itCanBeCreatedWithAnIsoString(): void { $pair = CurrencyPair::createFromIso('EUR/USD 1.2500'); diff --git a/tests/CurrencyTest.php b/tests/CurrencyTest.php index 2500991a..9d6af57e 100644 --- a/tests/CurrencyTest.php +++ b/tests/CurrencyTest.php @@ -12,33 +12,25 @@ /** @covers \Money\Currency */ final class CurrencyTest extends TestCase { - /** - * @test - */ + /** @test */ public function itConvertsToJson(): void { self::assertEquals('"USD"', json_encode(new Currency('USD'))); } - /** - * @test - */ + /** @test */ public function itAppliesUppercase(): void { self::assertEquals('USD', (new Currency('usd'))->getCode()); } - /** - * @test - */ + /** @test */ public function itIsStringable(): void { self::assertEquals('USD', (string) new Currency('usd')); } - /** - * @test - */ + /** @test */ public function itProvidesEqualityComparison(): void { $currency = new Currency('usd'); diff --git a/tests/Exchange/IndirectExchangeTest.php b/tests/Exchange/IndirectExchangeTest.php index ad30c794..eda122a7 100644 --- a/tests/Exchange/IndirectExchangeTest.php +++ b/tests/Exchange/IndirectExchangeTest.php @@ -14,9 +14,7 @@ /** @covers \Money\Exchange\IndirectExchange */ final class IndirectExchangeTest extends TestCase { - /** - * @test - */ + /** @test */ public function itCalculatesAMinimalChain(): void { $exchange = $this->createExchange(); @@ -51,9 +49,7 @@ private function createExchange(): IndirectExchange return new IndirectExchange($baseExchange, new ISOCurrencies()); } - /** - * @test - */ + /** @test */ public function itCalculatesAdjacentNodes(): void { $exchange = $this->createExchange(); @@ -65,9 +61,7 @@ public function itCalculatesAdjacentNodes(): void self::assertEquals(4, $pair->getConversionRatio()); } - /** - * @test - */ + /** @test */ public function itThrowsWhenNoChainIsFound(): void { $exchange = $this->createExchange(); diff --git a/tests/Exchange/ReversedCurrenciesExchangeTest.php b/tests/Exchange/ReversedCurrenciesExchangeTest.php index 8becd4e1..6b25bcf3 100644 --- a/tests/Exchange/ReversedCurrenciesExchangeTest.php +++ b/tests/Exchange/ReversedCurrenciesExchangeTest.php @@ -28,7 +28,7 @@ public function it_exchanges_currencies(): void self::assertEquals( new CurrencyPair($base, $counter, '1.25'), (new ReversedCurrenciesExchange($wrappedExchange)) - ->quote($base, $counter) + ->quote($base, $counter), ); } @@ -40,7 +40,7 @@ public function it_exchanges_reversed_currencies_when_the_original_pair_is_not_f $wrappedExchange = $this->createMock(Exchange::class); $wrappedExchange->method('quote') - ->willReturnCallback(static function (Currency $givenBase, Currency $givenCounter) use ($base + ->willReturnCallback(static function (Currency $givenBase, Currency $givenCounter) use ($base, ): CurrencyPair { if ($givenBase->equals($base)) { throw new UnresolvableCurrencyPairException(); @@ -52,7 +52,7 @@ public function it_exchanges_reversed_currencies_when_the_original_pair_is_not_f self::assertEquals( new CurrencyPair($base, $counter, '0.80000000000000'), (new ReversedCurrenciesExchange($wrappedExchange)) - ->quote($base, $counter) + ->quote($base, $counter), ); } @@ -66,7 +66,7 @@ public function it_throws_an_exception_when_neither_the_original_nor_the_reverse $wrappedExchange = $this->createMock(Exchange::class); $wrappedExchange->method('quote') - ->willReturnCallback(static function (Currency $givenBase) use ($exception2, $exception1, $base + ->willReturnCallback(static function (Currency $givenBase) use ($exception2, $exception1, $base, ): CurrencyPair { if ($givenBase->equals($base)) { throw $exception1; diff --git a/tests/Exchange/SwapExchangeTest.php b/tests/Exchange/SwapExchangeTest.php index a9978fab..b084a396 100644 --- a/tests/Exchange/SwapExchangeTest.php +++ b/tests/Exchange/SwapExchangeTest.php @@ -56,7 +56,7 @@ public function it_exchanges_currencies(float $exchangeRateValue, string $expect self::assertEquals( new CurrencyPair($base, $counter, $expectedConversionRatio), (new SwapExchange($swapExchange)) - ->quote($base, $counter) + ->quote($base, $counter), ); } diff --git a/tests/Formatter/AggregateMoneyFormatterTest.php b/tests/Formatter/AggregateMoneyFormatterTest.php index fc890495..546de7ff 100644 --- a/tests/Formatter/AggregateMoneyFormatterTest.php +++ b/tests/Formatter/AggregateMoneyFormatterTest.php @@ -27,7 +27,7 @@ public function it_formats_money(): void self::assertEquals( 'FIRST', (new AggregateMoneyFormatter(['EUR' => $eurFormatter])) - ->format($money) + ->format($money), ); } diff --git a/tests/Formatter/BitcoinMoneyFormatterTest.php b/tests/Formatter/BitcoinMoneyFormatterTest.php index 85be82c0..fb7cfcd9 100644 --- a/tests/Formatter/BitcoinMoneyFormatterTest.php +++ b/tests/Formatter/BitcoinMoneyFormatterTest.php @@ -33,7 +33,7 @@ public function itFormatsMoney(int $value, string $formatted, int $fractionDigit self::assertSame( $formatted, (new BitcoinMoneyFormatter($fractionDigits, $currencies)) - ->format(new Money($value, $currency)) + ->format(new Money($value, $currency)), ); } diff --git a/tests/MoneyTest.php b/tests/MoneyTest.php index 1827ba8d..a03daead 100644 --- a/tests/MoneyTest.php +++ b/tests/MoneyTest.php @@ -94,9 +94,7 @@ public function itMultipliesTheAmount(int|string $multiplier, int $roundingMode, self::assertEquals($result, $money->getAmount()); } - /** - * @test - */ + /** @test */ public function itMultipliesTheAmountWithLocaleThatUsesCommaSeparator(): void { $this->setLocale(LC_ALL, 'es_ES.utf8'); @@ -125,7 +123,7 @@ public function it_divides_the_amount(int|string $divisor, int $roundingMode, st ->multiply($divisor, $roundingMode) ->divide($divisor, $roundingMode) ->getAmount(), - 'Our dataset does not contain a lot of data around divisions: we abuse multiplication to verify inverse function properties' + 'Our dataset does not contain a lot of data around divisions: we abuse multiplication to verify inverse function properties', ); } @@ -275,9 +273,7 @@ public function itCalculatesTheModulusOfNumber($left, $right, $expected): void self::assertEquals($expected, $money->getAmount()); } - /** - * @test - */ + /** @test */ public function itThrowsWhenDivisorIsInvalidStringArgument(): void { $money = new Money(self::AMOUNT, new Currency(self::CURRENCY)); @@ -288,9 +284,7 @@ public function itThrowsWhenDivisorIsInvalidStringArgument(): void $money->mod('test'); } - /** - * @test - */ + /** @test */ public function itThrowsWhenCalculatingModulusOfDifferentCurrencies(): void { $money = new Money(self::AMOUNT, new Currency(self::CURRENCY)); @@ -302,25 +296,21 @@ public function itThrowsWhenCalculatingModulusOfDifferentCurrencies(): void $money->mod($rightMoney); } - /** - * @test - */ + /** @test */ public function itConvertsToJson(): void { self::assertEquals( '{"amount":"350","currency":"EUR"}', - json_encode(Money::EUR(350)) + json_encode(Money::EUR(350)), ); self::assertEquals( ['amount' => '350', 'currency' => 'EUR'], - Money::EUR(350)->jsonSerialize() + Money::EUR(350)->jsonSerialize(), ); } - /** - * @test - */ + /** @test */ public function itSupportsMaxInt(): void { $one = new Money(1, new Currency('EUR')); @@ -330,9 +320,7 @@ public function itSupportsMaxInt(): void self::assertInstanceOf(Money::class, (new Money(PHP_INT_MAX, new Currency('EUR')))->subtract($one)); } - /** - * @test - */ + /** @test */ public function itReturnsRatioOf(): void { $currency = new Currency('EUR'); @@ -346,9 +334,7 @@ public function itReturnsRatioOf(): void self::assertEquals(2, $six->ratioOf($three)); } - /** - * @test - */ + /** @test */ public function itThrowsWhenCalculatingRatioOfZero(): void { $currency = new Currency('EUR'); @@ -360,9 +346,7 @@ public function itThrowsWhenCalculatingRatioOfZero(): void $six->ratioOf($zero); } - /** - * @test - */ + /** @test */ public function itThrowsWhenCalculatingRatioOfDifferentCurrencies(): void { $money = new Money(self::AMOUNT, new Currency(self::CURRENCY)); @@ -438,9 +422,7 @@ public function itThrowsWithDecimal(): void new Money('5.1', new Currency(self::CURRENCY)); } - /** - * @test - */ + /** @test */ public function itThrowsWhenComparingDifferentCurrencies(): void { $money = new Money('5', new Currency(self::CURRENCY)); diff --git a/tests/NumberTest.php b/tests/NumberTest.php index 08e5aa47..e8443bd5 100644 --- a/tests/NumberTest.php +++ b/tests/NumberTest.php @@ -81,7 +81,7 @@ public function itCreatesANumberFromAFloatingPointValue(): void { self::assertEquals( Number::fromString('123.456789'), - Number::fromFloat(123.456789) + Number::fromFloat(123.456789), ); } diff --git a/tests/Parser/AggregateMoneyParserTest.php b/tests/Parser/AggregateMoneyParserTest.php index 1ecb0091..f644cf89 100644 --- a/tests/Parser/AggregateMoneyParserTest.php +++ b/tests/Parser/AggregateMoneyParserTest.php @@ -27,7 +27,7 @@ public function it_parses_money(): void self::assertEquals( $money, (new AggregateMoneyParser([$wrappedParser])) - ->parse('€ 100') + ->parse('€ 100'), ); } @@ -77,7 +77,7 @@ public function it_will_retrieve_parser_result_from_first_successful_parser(): v self::assertEquals( $money, (new AggregateMoneyParser([$wrappedParser1, $wrappedParser2, $wrappedParser3])) - ->parse('€ 100') + ->parse('€ 100'), ); } } diff --git a/tests/Parser/BitcoinMoneyParserTest.php b/tests/Parser/BitcoinMoneyParserTest.php index 4a7eb1f0..d167ea7a 100644 --- a/tests/Parser/BitcoinMoneyParserTest.php +++ b/tests/Parser/BitcoinMoneyParserTest.php @@ -31,9 +31,7 @@ public function itParsesMoney(string $string, int|string $units): void self::assertEquals(BitcoinCurrencies::CODE, $money->getCurrency()->getCode()); } - /** - * @test - */ + /** @test */ public function forceCurrencyWorks(): void { $moneyParser = new BitcoinMoneyParser(2); diff --git a/tests/Parser/DecimalMoneyParserTest.php b/tests/Parser/DecimalMoneyParserTest.php index 28fdd9f0..0ade2e56 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 7bf4d9c0..881febef 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'; @@ -40,9 +40,7 @@ public function itParsesMoney(string $string, int $units, string $locale): void self::assertEquals($units, $parser->parse($string, $currency)->getAmount()); } - /** - * @test - */ + /** @test */ public function itCannotConvertStringToUnits(): void { $formatter = new NumberFormatter('en_US', NumberFormatter::DECIMAL); @@ -54,9 +52,7 @@ public function itCannotConvertStringToUnits(): void $parser->parse('THIS_IS_NOT_CONVERTABLE_TO_UNIT', $currency); } - /** - * @test - */ + /** @test */ public function itWorksWithAllKindsOfLocales(): void { $formatter = new NumberFormatter('en_CA', NumberFormatter::DECIMAL); @@ -67,9 +63,7 @@ public function itWorksWithAllKindsOfLocales(): void self::assertTrue(Money::CAD(100000)->equals($money)); } - /** - * @test - */ + /** @test */ public function itAcceptsAForcedCurrency(): void { $formatter = new NumberFormatter('en_US', NumberFormatter::DECIMAL); @@ -82,9 +76,7 @@ public function itAcceptsAForcedCurrency(): void self::assertSame('CAD', $money->getCurrency()->getCode()); } - /** - * @test - */ + /** @test */ public function itSupportsFractionDigits(): void { $formatter = new NumberFormatter('en_US', NumberFormatter::DECIMAL); @@ -96,9 +88,7 @@ public function itSupportsFractionDigits(): void self::assertSame('100001', $money->getAmount()); } - /** - * @test - */ + /** @test */ public function it_does_not_support_invalid_decimal(): void { $formatter = new NumberFormatter('en_US', NumberFormatter::DECIMAL); diff --git a/tests/Parser/IntlMoneyParserTest.php b/tests/Parser/IntlMoneyParserTest.php index a1b726f0..3cb3dd03 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'; @@ -40,9 +40,7 @@ public function itParsesMoney(string $string, int $units): void self::assertEquals($units, $parser->parse($string, $currency)->getAmount()); } - /** - * @test - */ + /** @test */ public function itCannotConvertStringToUnits(): void { $formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY); @@ -56,9 +54,7 @@ public function itCannotConvertStringToUnits(): void $parser->parse('THIS_IS_NOT_CONVERTABLE_TO_UNIT', $currency); } - /** - * @test - */ + /** @test */ public function itWorksWithAllKindsOfLocales(): void { $formatter = new NumberFormatter('en_CA', NumberFormatter::CURRENCY); @@ -70,9 +66,7 @@ public function itWorksWithAllKindsOfLocales(): void self::assertTrue(Money::CAD(100000)->equals($money)); } - /** - * @test - */ + /** @test */ public function itAcceptsAForcedCurrency(): void { $formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY); @@ -87,9 +81,7 @@ public function itAcceptsAForcedCurrency(): void self::assertEquals('CAD', $money->getCurrency()->getCode()); } - /** - * @test - */ + /** @test */ public function itSupportsFractionDigits(): void { $formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY); diff --git a/tests/TellerTest.php b/tests/TellerTest.php index 2725a284..c137f296 100644 --- a/tests/TellerTest.php +++ b/tests/TellerTest.php @@ -17,9 +17,7 @@ protected function setUp(): void $this->teller = Teller::USD(); } - /** - * @test - */ + /** @test */ public function itDemonstratesThePenniesProblem(): void { $amount1 = 1.23; @@ -31,9 +29,7 @@ public function itDemonstratesThePenniesProblem(): void $actual = $amount1 * $amount2; $expect = 5.6088; - /** - * @psalm-suppress RedundantCondition - */ + /** @psalm-suppress RedundantCondition */ $this->assertSame($expect, $actual); // instead, use the Teller to do monetary math. @@ -42,9 +38,7 @@ public function itDemonstratesThePenniesProblem(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itComparesEqualAmounts(): void { $this->assertTrue($this->teller->equals('7.00', 7.00)); @@ -52,9 +46,7 @@ public function itComparesEqualAmounts(): void $this->assertTrue($this->teller->equals(7, 7.00)); } - /** - * @test - */ + /** @test */ public function itComparesTwoAmounts(): void { $amount = 1.23; @@ -65,17 +57,13 @@ public function itComparesTwoAmounts(): void $this->assertSame(+1, $this->teller->compare($other, $amount)); } - /** - * @test - */ + /** @test */ public function itComparesGreaterThanAmounts(): void { $this->assertTrue($this->teller->greaterThan('45.67', '9.01')); } - /** - * @test - */ + /** @test */ public function itComparesGreaterThanOrEqualAmounts(): void { $this->assertTrue($this->teller->greaterThanOrEqual('45.67', '9.01')); @@ -85,17 +73,13 @@ public function itComparesGreaterThanOrEqualAmounts(): void $this->assertFalse($this->teller->greaterThanOrEqual(7, 7.01)); } - /** - * @test - */ + /** @test */ public function itComparesLessThanAmounts(): void { $this->assertTrue($this->teller->lessThan('9.01', '45.67')); } - /** - * @test - */ + /** @test */ public function itComparesLessThanOrEqualAmounts(): void { $this->assertTrue($this->teller->lessThanOrEqual('9.01', '45.67')); @@ -105,9 +89,7 @@ public function itComparesLessThanOrEqualAmounts(): void $this->assertFalse($this->teller->lessThanOrEqual(7, 6.99)); } - /** - * @test - */ + /** @test */ public function itAddsAmounts(): void { $actual = $this->teller->add(1.1, '2.2', 3, 4.44, '5.55'); @@ -115,9 +97,7 @@ public function itAddsAmounts(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itSubtractsAmounts(): void { $actual = $this->teller->subtract(1.1, '2.2', 3, 4.44, '5.55'); @@ -125,9 +105,7 @@ public function itSubtractsAmounts(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itMultipliesAmounts(): void { $amount = 1.23; @@ -138,9 +116,7 @@ public function itMultipliesAmounts(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itMultipliesNegativeAmounts(): void { $amount = '-0.09'; @@ -180,9 +156,7 @@ public function itMultipliesNegativeAmounts(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itDividesAmounts(): void { $amount = 1.23; @@ -193,9 +167,7 @@ public function itDividesAmounts(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itDividesNegativeAmounts(): void { $amount = '-0.09'; @@ -229,9 +201,7 @@ public function itDividesNegativeAmounts(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itModsAmounts(): void { $amount = '10'; @@ -241,9 +211,7 @@ public function itModsAmounts(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itAllocatesAmountsAcrossRatios(): void { $amount = '100.00'; @@ -257,9 +225,7 @@ public function itAllocatesAmountsAcrossRatios(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itAllocatesAmountsAmongTargets(): void { $amount = '100.00'; @@ -273,9 +239,7 @@ public function itAllocatesAmountsAmongTargets(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itCalculatesRatiosOfAmounts(): void { $amount = '100.00'; @@ -285,36 +249,28 @@ public function itCalculatesRatiosOfAmounts(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itCalculatesAbsoluteAmount(): void { $this->assertSame('7.00', $this->teller->absolute(-7)); $this->assertSame('7.00', $this->teller->absolute(7.0)); } - /** - * @test - */ + /** @test */ public function itCalculatesNegativeAmount(): void { $this->assertSame('-7.00', $this->teller->negative(7)); $this->assertSame('7.00', $this->teller->negative(-7)); } - /** - * @test - */ + /** @test */ public function itComparesAnAmountToZero(): void { $this->assertTrue($this->teller->isZero(0.00)); $this->assertFalse($this->teller->isZero(0.01)); } - /** - * @test - */ + /** @test */ public function itTellsIfAnAmountIsPositive(): void { $this->assertTrue($this->teller->isPositive(1)); @@ -322,9 +278,7 @@ public function itTellsIfAnAmountIsPositive(): void $this->assertFalse($this->teller->isPositive(-1)); } - /** - * @test - */ + /** @test */ public function itTellsIfAnAmountIsNegative(): void { $this->assertFalse($this->teller->isNegative(1)); @@ -332,9 +286,7 @@ public function itTellsIfAnAmountIsNegative(): void $this->assertTrue($this->teller->isNegative(-1)); } - /** - * @test - */ + /** @test */ public function itFindsTheMinimumAmount(): void { $amounts = [ @@ -349,9 +301,7 @@ public function itFindsTheMinimumAmount(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itFindsTheMaximumAmount(): void { $amounts = [ @@ -366,9 +316,7 @@ public function itFindsTheMaximumAmount(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itSumsAmounts(): void { $amounts = [ @@ -383,9 +331,7 @@ public function itSumsAmounts(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itAveragesAmounts(): void { $amounts = [ @@ -400,17 +346,13 @@ public function itAveragesAmounts(): void $this->assertSame($expect, $actual); } - /** - * @test - */ + /** @test */ public function itReturnsAZeroString(): void { $this->assertSame('0.00', $this->teller->zero()); } - /** - * @test - */ + /** @test */ public function itConvertsMonetaryAmounts(): void { $money = $this->teller->convertToMoney('1.23'); From 1e2523b70f298ad7718b2d44e7b7e72875fb8f4b Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Fri, 26 Jan 2024 13:41:14 +0100 Subject: [PATCH 4/4] feat: bump dev-dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 93a7abd0..30487e8e 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "doctrine/instantiator": "^1.5.0 || ^2.0", "florianv/exchanger": "^2.8.1", "florianv/swap": "^4.3.0", - "moneyphp/iso-currencies": "^3.3 || ^4.0", + "moneyphp/iso-currencies": "^3.4", "moneyphp/crypto-currencies": "^1.1.0", "php-http/message": "^1.16.0", "php-http/mock-client": "^1.6.0",