Skip to content

Commit

Permalink
Resolve PHP 8.4 deprecations (fix #24)
Browse files Browse the repository at this point in the history
  • Loading branch information
stancl committed Dec 29, 2024
1 parent 8a0eeae commit b642e32
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ parameters:
message: '#Unsafe usage of new static#'
paths:
- src/Currency.php

checkMissingIterableValueType: false
- identifier: missingType.iterableValue
22 changes: 11 additions & 11 deletions src/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '';
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidCurrencyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class InvalidCurrencyException extends Exception
{
public function __construct(string $message = null)
public function __construct(?string $message = null)
{
parent::__construct($message ?? 'The currency is invalid');
}
Expand Down
8 changes: 4 additions & 4 deletions src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -34,7 +34,7 @@ protected function newFromDecimal(float $decimal): self
}

/** 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())),
Expand Down Expand Up @@ -179,7 +179,7 @@ public function rawFormatted(mixed ...$overrides): string
* @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)
Expand Down Expand Up @@ -277,7 +277,7 @@ public function toDefault(): self
}

/** 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();

Expand Down
4 changes: 2 additions & 2 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

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());
}
}

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
Expand Down

0 comments on commit b642e32

Please sign in to comment.