1
0
Fork 0
mirror of https://github.com/archtechx/money.git synced 2025-12-12 03:14:03 +00:00

Resolve PHP 8.4 deprecations (fix #24)

This commit is contained in:
Samuel Štancl 2024-12-29 03:10:59 +01:00
parent 8a0eeae7c7
commit b642e32a4b
6 changed files with 22 additions and 23 deletions

View file

@ -23,7 +23,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.4'
- name: Install composer dependencies
run: composer require "illuminate/support:^${{ matrix.laravel }}.0"
- name: Run tests
@ -38,7 +38,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.4'
- name: Install composer dependencies
run: composer install
- name: Run phpstan
@ -52,7 +52,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.3'
- name: Install php-cs-fixer
run: composer global require friendsofphp/php-cs-fixer
- name: Run php-cs-fixer

View file

@ -22,5 +22,4 @@ parameters:
message: '#Unsafe usage of new static#'
paths:
- src/Currency.php
checkMissingIterableValueType: false
- identifier: missingType.iterableValue

View file

@ -46,17 +46,17 @@ class Currency implements Arrayable, JsonSerializable
/** Create a new Currency instance. */
public function __construct(
string $code = null,
string $name = null,
float $rate = null,
string $prefix = null,
string $suffix = null,
int $mathDecimals = null,
int $displayDecimals = null,
int $rounding = null,
string $decimalSeparator = null,
string $thousandsSeparator = null,
bool $trimTrailingDecimalZeros = null,
?string $code = null,
?string $name = null,
?float $rate = null,
?string $prefix = null,
?string $suffix = null,
?int $mathDecimals = null,
?int $displayDecimals = null,
?int $rounding = null,
?string $decimalSeparator = null,
?string $thousandsSeparator = null,
?bool $trimTrailingDecimalZeros = null,
) {
$this->code = $code ?? $this->code ?? '';
$this->name = $name ?? $this->name ?? '';

View file

@ -8,7 +8,7 @@ use Exception;
class InvalidCurrencyException extends Exception
{
public function __construct(string $message = null)
public function __construct(?string $message = null)
{
parent::__construct($message ?? 'The currency is invalid');
}

View file

@ -15,7 +15,7 @@ final class Money implements JsonSerializable, Arrayable, Wireable
protected Currency $currency;
/** Create a new Money instance. */
public function __construct(int $value, Currency|string $currency = null)
public function __construct(int $value, Currency|string|null $currency = null)
{
$this->value = $value;
$this->currency = currency($currency);
@ -34,7 +34,7 @@ final class Money implements JsonSerializable, Arrayable, Wireable
}
/** Create a Money instance from a decimal value. */
public static function fromDecimal(float $decimal, Currency|string $currency = null): self
public static function fromDecimal(float $decimal, Currency|string|null $currency = null): self
{
return new static(
(int) round($decimal * pow(10, currency($currency)->mathDecimals())),
@ -179,7 +179,7 @@ final class Money implements JsonSerializable, Arrayable, Wireable
* @param Currency|string|null $currency The currency to use when passing the overrides. If not provided, the currency of the formatted string is used.
* @param array ...$overrides The overrides used when formatting the money instance.
*/
public static function fromFormatted(string $formatted, Currency|string $currency = null, mixed ...$overrides): self
public static function fromFormatted(string $formatted, Currency|string|null $currency = null, mixed ...$overrides): self
{
$currency = isset($currency)
? currency($currency)
@ -277,7 +277,7 @@ final class Money implements JsonSerializable, Arrayable, Wireable
}
/** Round the Money to a custom precision. */
public function rounded(int $precision = null): self
public function rounded(?int $precision = null): self
{
$precision ??= $this->currency->rounding();

View file

@ -8,7 +8,7 @@ use ArchTech\Money\Money;
if (! function_exists('money')) {
/** Create a Money instance. */
function money(int $amount, Currency|string $currency = null): Money
function money(int $amount, Currency|string|null $currency = null): Money
{
return new Money($amount, $currency ?? currencies()->getDefault());
}
@ -16,7 +16,7 @@ if (! function_exists('money')) {
if (! function_exists('currency')) {
/** Fetch a currency. If no argument is provided, the current currency will be returned. */
function currency(Currency|string $currency = null): Currency
function currency(Currency|string|null $currency = null): Currency
{
if ($currency) {
return $currency instanceof Currency