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

View file

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

View file

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

View file

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

View file

@ -15,7 +15,7 @@ final class Money implements JsonSerializable, Arrayable, Wireable
protected Currency $currency; protected Currency $currency;
/** Create a new Money instance. */ /** 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->value = $value;
$this->currency = currency($currency); $this->currency = currency($currency);
@ -34,7 +34,7 @@ final class Money implements JsonSerializable, Arrayable, Wireable
} }
/** Create a Money instance from a decimal value. */ /** 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( return new static(
(int) round($decimal * pow(10, currency($currency)->mathDecimals())), (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 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. * @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 = isset($currency)
? currency($currency) ? currency($currency)
@ -277,7 +277,7 @@ final class Money implements JsonSerializable, Arrayable, Wireable
} }
/** Round the Money to a custom precision. */ /** 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(); $precision ??= $this->currency->rounding();

View file

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