diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fca2e98..2148426 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/phpstan.neon b/phpstan.neon index e064b98..2d7efab 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -22,5 +22,4 @@ parameters: message: '#Unsafe usage of new static#' paths: - src/Currency.php - - checkMissingIterableValueType: false + - identifier: missingType.iterableValue diff --git a/src/Currency.php b/src/Currency.php index c2db2a4..3c80aa9 100644 --- a/src/Currency.php +++ b/src/Currency.php @@ -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 ?? ''; diff --git a/src/Exceptions/InvalidCurrencyException.php b/src/Exceptions/InvalidCurrencyException.php index 8b0e7b4..d705cfa 100644 --- a/src/Exceptions/InvalidCurrencyException.php +++ b/src/Exceptions/InvalidCurrencyException.php @@ -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'); } diff --git a/src/Money.php b/src/Money.php index 6eaa6a7..b8f5f6f 100644 --- a/src/Money.php +++ b/src/Money.php @@ -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 @@ 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())), @@ -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) @@ -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(); diff --git a/src/helpers.php b/src/helpers.php index 9fa6f61..d2f2764 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -8,7 +8,7 @@ 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 @@ function money(int $amount, Currency|string $currency = null): 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