Skip to content

Commit b642e32

Browse files
committed
Resolve PHP 8.4 deprecations (fix #24)
1 parent 8a0eeae commit b642e32

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Setup PHP
2424
uses: shivammathur/setup-php@v2
2525
with:
26-
php-version: '8.2'
26+
php-version: '8.4'
2727
- name: Install composer dependencies
2828
run: composer require "illuminate/support:^${{ matrix.laravel }}.0"
2929
- name: Run tests
@@ -38,7 +38,7 @@ jobs:
3838
- name: Setup PHP
3939
uses: shivammathur/setup-php@v2
4040
with:
41-
php-version: '8.2'
41+
php-version: '8.4'
4242
- name: Install composer dependencies
4343
run: composer install
4444
- name: Run phpstan
@@ -52,7 +52,7 @@ jobs:
5252
- name: Setup PHP
5353
uses: shivammathur/setup-php@v2
5454
with:
55-
php-version: '8.2'
55+
php-version: '8.3'
5656
- name: Install php-cs-fixer
5757
run: composer global require friendsofphp/php-cs-fixer
5858
- name: Run php-cs-fixer

phpstan.neon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ parameters:
2222
message: '#Unsafe usage of new static#'
2323
paths:
2424
- src/Currency.php
25-
26-
checkMissingIterableValueType: false
25+
- identifier: missingType.iterableValue

src/Currency.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ class Currency implements Arrayable, JsonSerializable
4646

4747
/** Create a new Currency instance. */
4848
public function __construct(
49-
string $code = null,
50-
string $name = null,
51-
float $rate = null,
52-
string $prefix = null,
53-
string $suffix = null,
54-
int $mathDecimals = null,
55-
int $displayDecimals = null,
56-
int $rounding = null,
57-
string $decimalSeparator = null,
58-
string $thousandsSeparator = null,
59-
bool $trimTrailingDecimalZeros = null,
49+
?string $code = null,
50+
?string $name = null,
51+
?float $rate = null,
52+
?string $prefix = null,
53+
?string $suffix = null,
54+
?int $mathDecimals = null,
55+
?int $displayDecimals = null,
56+
?int $rounding = null,
57+
?string $decimalSeparator = null,
58+
?string $thousandsSeparator = null,
59+
?bool $trimTrailingDecimalZeros = null,
6060
) {
6161
$this->code = $code ?? $this->code ?? '';
6262
$this->name = $name ?? $this->name ?? '';

src/Exceptions/InvalidCurrencyException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class InvalidCurrencyException extends Exception
1010
{
11-
public function __construct(string $message = null)
11+
public function __construct(?string $message = null)
1212
{
1313
parent::__construct($message ?? 'The currency is invalid');
1414
}

src/Money.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class Money implements JsonSerializable, Arrayable, Wireable
1515
protected Currency $currency;
1616

1717
/** Create a new Money instance. */
18-
public function __construct(int $value, Currency|string $currency = null)
18+
public function __construct(int $value, Currency|string|null $currency = null)
1919
{
2020
$this->value = $value;
2121
$this->currency = currency($currency);
@@ -34,7 +34,7 @@ protected function newFromDecimal(float $decimal): self
3434
}
3535

3636
/** Create a Money instance from a decimal value. */
37-
public static function fromDecimal(float $decimal, Currency|string $currency = null): self
37+
public static function fromDecimal(float $decimal, Currency|string|null $currency = null): self
3838
{
3939
return new static(
4040
(int) round($decimal * pow(10, currency($currency)->mathDecimals())),
@@ -179,7 +179,7 @@ public function rawFormatted(mixed ...$overrides): string
179179
* @param Currency|string|null $currency The currency to use when passing the overrides. If not provided, the currency of the formatted string is used.
180180
* @param array ...$overrides The overrides used when formatting the money instance.
181181
*/
182-
public static function fromFormatted(string $formatted, Currency|string $currency = null, mixed ...$overrides): self
182+
public static function fromFormatted(string $formatted, Currency|string|null $currency = null, mixed ...$overrides): self
183183
{
184184
$currency = isset($currency)
185185
? currency($currency)
@@ -277,7 +277,7 @@ public function toDefault(): self
277277
}
278278

279279
/** Round the Money to a custom precision. */
280-
public function rounded(int $precision = null): self
280+
public function rounded(?int $precision = null): self
281281
{
282282
$precision ??= $this->currency->rounding();
283283

src/helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
if (! function_exists('money')) {
1010
/** Create a Money instance. */
11-
function money(int $amount, Currency|string $currency = null): Money
11+
function money(int $amount, Currency|string|null $currency = null): Money
1212
{
1313
return new Money($amount, $currency ?? currencies()->getDefault());
1414
}
1515
}
1616

1717
if (! function_exists('currency')) {
1818
/** Fetch a currency. If no argument is provided, the current currency will be returned. */
19-
function currency(Currency|string $currency = null): Currency
19+
function currency(Currency|string|null $currency = null): Currency
2020
{
2121
if ($currency) {
2222
return $currency instanceof Currency

0 commit comments

Comments
 (0)