Skip to content

Commit 0be5309

Browse files
committed
PHP 8+ Union types
1 parent 725715a commit 0be5309

18 files changed

+100
-177
lines changed

rector.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
__DIR__ . '/tests',
1919
]);
2020

21-
$parameters->set(Option::SKIP, [
22-
UnionTypesRector::class
23-
]);
24-
2521
// Define what rule sets will be applied
2622
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_91);
2723
$containerConfigurator->import(LaravelSetList::LARAVEL_80);

src/Interfaces/Discount.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,5 @@
66

77
interface Discount
88
{
9-
/**
10-
* @return float|int
11-
*/
12-
public function getPersonalDiscount(Customer $customer);
9+
public function getPersonalDiscount(Customer $customer): float|int;
1310
}

src/Interfaces/Exchangeable.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
interface Exchangeable
1818
{
1919
/**
20-
* @param int|string $amount
21-
*
2220
* @throws BalanceIsEmpty
2321
* @throws InsufficientFunds
2422
* @throws LockProviderNotFoundException
@@ -27,21 +25,16 @@ interface Exchangeable
2725
* @throws TransactionFailedException
2826
* @throws ExceptionInterface
2927
*/
30-
public function exchange(Wallet $to, $amount, ExtraDtoInterface|array|null $meta = null): Transfer;
28+
public function exchange(Wallet $to, int|string $amount, ExtraDtoInterface|array|null $meta = null): Transfer;
3129

32-
/**
33-
* @param int|string $amount
34-
*/
35-
public function safeExchange(Wallet $to, $amount, ExtraDtoInterface|array|null $meta = null): ?Transfer;
30+
public function safeExchange(Wallet $to, int|string $amount, ExtraDtoInterface|array|null $meta = null): ?Transfer;
3631

3732
/**
38-
* @param int|string $amount
39-
*
4033
* @throws LockProviderNotFoundException
4134
* @throws RecordNotFoundException
4235
* @throws RecordsNotFoundException
4336
* @throws TransactionFailedException
4437
* @throws ExceptionInterface
4538
*/
46-
public function forceExchange(Wallet $to, $amount, ExtraDtoInterface|array|null $meta = null): Transfer;
39+
public function forceExchange(Wallet $to, int|string $amount, ExtraDtoInterface|array|null $meta = null): Transfer;
4740
}

src/Interfaces/MaximalTaxable.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,5 @@
66

77
interface MaximalTaxable extends Taxable
88
{
9-
/**
10-
* @return float|int
11-
*/
12-
public function getMaximalFee();
9+
public function getMaximalFee(): float|int;
1310
}

src/Interfaces/MinimalTaxable.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,5 @@
66

77
interface MinimalTaxable extends Taxable
88
{
9-
/**
10-
* @return float|int
11-
*/
12-
public function getMinimalFee();
9+
public function getMinimalFee(): float|int;
1310
}

src/Interfaces/ProductInterface.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
interface ProductInterface extends Wallet
88
{
9-
/**
10-
* @return float|int|string
11-
*/
12-
public function getAmountProduct(Customer $customer);
9+
public function getAmountProduct(Customer $customer): float|int|string;
1310

1411
public function getMetaProduct(): ?array;
1512
}

src/Interfaces/Taxable.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ interface Taxable
1010
* Specify the percentage of the amount. For example, the product costs $100, the equivalent of 15%. That's $115.
1111
*
1212
* Minimum 0; Maximum 100 Example: return 7.5; // 7.5%
13-
*
14-
* @return float|int
1513
*/
16-
public function getFeePercent();
14+
public function getFeePercent(): float|int;
1715
}

src/Interfaces/Wallet.php

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,15 @@
2020
interface Wallet
2121
{
2222
/**
23-
* @param int|string $amount
24-
*
2523
* @throws AmountInvalid
2624
* @throws LockProviderNotFoundException
2725
* @throws RecordsNotFoundException
2826
* @throws TransactionFailedException
2927
* @throws ExceptionInterface
3028
*/
31-
public function deposit($amount, ?array $meta = null, bool $confirmed = true): Transaction;
29+
public function deposit(int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction;
3230

3331
/**
34-
* @param int|string $amount
35-
*
3632
* @throws AmountInvalid
3733
* @throws BalanceIsEmpty
3834
* @throws InsufficientFunds
@@ -41,22 +37,18 @@ public function deposit($amount, ?array $meta = null, bool $confirmed = true): T
4137
* @throws TransactionFailedException
4238
* @throws ExceptionInterface
4339
*/
44-
public function withdraw($amount, ?array $meta = null, bool $confirmed = true): Transaction;
40+
public function withdraw(int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction;
4541

4642
/**
47-
* @param int|string $amount
48-
*
4943
* @throws AmountInvalid
5044
* @throws LockProviderNotFoundException
5145
* @throws RecordsNotFoundException
5246
* @throws TransactionFailedException
5347
* @throws ExceptionInterface
5448
*/
55-
public function forceWithdraw($amount, ?array $meta = null, bool $confirmed = true): Transaction;
49+
public function forceWithdraw(int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction;
5650

5751
/**
58-
* @param int|string $amount
59-
*
6052
* @throws AmountInvalid
6153
* @throws BalanceIsEmpty
6254
* @throws InsufficientFunds
@@ -65,33 +57,30 @@ public function forceWithdraw($amount, ?array $meta = null, bool $confirmed = tr
6557
* @throws TransactionFailedException
6658
* @throws ExceptionInterface
6759
*/
68-
public function transfer(self $wallet, $amount, ExtraDtoInterface|array|null $meta = null): Transfer;
60+
public function transfer(self $wallet, int|string $amount, ExtraDtoInterface|array|null $meta = null): Transfer;
6961

70-
/**
71-
* @param int|string $amount
72-
*/
73-
public function safeTransfer(self $wallet, $amount, ExtraDtoInterface|array|null $meta = null): ?Transfer;
62+
public function safeTransfer(
63+
self $wallet,
64+
int|string $amount,
65+
ExtraDtoInterface|array|null $meta = null
66+
): ?Transfer;
7467

7568
/**
76-
* @param int|string $amount
77-
*
7869
* @throws AmountInvalid
7970
* @throws LockProviderNotFoundException
8071
* @throws RecordsNotFoundException
8172
* @throws TransactionFailedException
8273
* @throws ExceptionInterface
8374
*/
84-
public function forceTransfer(self $wallet, $amount, ExtraDtoInterface|array|null $meta = null): Transfer;
75+
public function forceTransfer(
76+
self $wallet,
77+
int|string $amount,
78+
ExtraDtoInterface|array|null $meta = null
79+
): Transfer;
8580

86-
/**
87-
* @param int|string $amount
88-
*/
89-
public function canWithdraw($amount, bool $allowZero = false): bool;
81+
public function canWithdraw(int|string $amount, bool $allowZero = false): bool;
9082

91-
/**
92-
* @return float|int
93-
*/
94-
public function getBalanceAttribute();
83+
public function getBalanceAttribute(): string;
9584

9685
public function getBalanceIntAttribute(): int;
9786

src/Interfaces/WalletFloat.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,15 @@
1818
interface WalletFloat
1919
{
2020
/**
21-
* @param float|string $amount
22-
*
2321
* @throws AmountInvalid
2422
* @throws LockProviderNotFoundException
2523
* @throws RecordsNotFoundException
2624
* @throws TransactionFailedException
2725
* @throws ExceptionInterface
2826
*/
29-
public function depositFloat($amount, ?array $meta = null, bool $confirmed = true): Transaction;
27+
public function depositFloat(float|int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction;
3028

3129
/**
32-
* @param float|string $amount
33-
*
3430
* @throws AmountInvalid
3531
* @throws BalanceIsEmpty
3632
* @throws InsufficientFunds
@@ -39,22 +35,22 @@ public function depositFloat($amount, ?array $meta = null, bool $confirmed = tru
3935
* @throws TransactionFailedException
4036
* @throws ExceptionInterface
4137
*/
42-
public function withdrawFloat($amount, ?array $meta = null, bool $confirmed = true): Transaction;
38+
public function withdrawFloat(float|int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction;
4339

4440
/**
45-
* @param float|string $amount
46-
*
4741
* @throws AmountInvalid
4842
* @throws LockProviderNotFoundException
4943
* @throws RecordsNotFoundException
5044
* @throws TransactionFailedException
5145
* @throws ExceptionInterface
5246
*/
53-
public function forceWithdrawFloat($amount, ?array $meta = null, bool $confirmed = true): Transaction;
47+
public function forceWithdrawFloat(
48+
float|int|string $amount,
49+
?array $meta = null,
50+
bool $confirmed = true
51+
): Transaction;
5452

5553
/**
56-
* @param float|string $amount
57-
*
5854
* @throws AmountInvalid
5955
* @throws BalanceIsEmpty
6056
* @throws InsufficientFunds
@@ -63,31 +59,35 @@ public function forceWithdrawFloat($amount, ?array $meta = null, bool $confirmed
6359
* @throws TransactionFailedException
6460
* @throws ExceptionInterface
6561
*/
66-
public function transferFloat(Wallet $wallet, $amount, ExtraDtoInterface|array|null $meta = null): Transfer;
62+
public function transferFloat(
63+
Wallet $wallet,
64+
float|int|string $amount,
65+
ExtraDtoInterface|array|null $meta = null
66+
): Transfer;
6767

68-
/**
69-
* @param float|string $amount
70-
*/
71-
public function safeTransferFloat(Wallet $wallet, $amount, ExtraDtoInterface|array|null $meta = null): ?Transfer;
68+
public function safeTransferFloat(
69+
Wallet $wallet,
70+
float|int|string $amount,
71+
ExtraDtoInterface|array|null $meta = null
72+
): ?Transfer;
7273

7374
/**
74-
* @param float|string $amount
75-
*
7675
* @throws AmountInvalid
7776
* @throws LockProviderNotFoundException
7877
* @throws RecordsNotFoundException
7978
* @throws TransactionFailedException
8079
* @throws ExceptionInterface
8180
*/
82-
public function forceTransferFloat(Wallet $wallet, $amount, ExtraDtoInterface|array|null $meta = null): Transfer;
81+
public function forceTransferFloat(
82+
Wallet $wallet,
83+
float|int|string $amount,
84+
ExtraDtoInterface|array|null $meta = null
85+
): Transfer;
8386

84-
/**
85-
* @param float|string $amount
86-
*/
87-
public function canWithdrawFloat($amount): bool;
87+
public function canWithdrawFloat(float|int|string $amount): bool;
8888

8989
/**
90-
* @return float|int|string
90+
* @return string
9191
*/
9292
public function getBalanceFloatAttribute();
9393
}

src/Models/Transaction.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ public function getAmountFloatAttribute(): string
9292
return $math->div($this->amount, $decimalPlaces);
9393
}
9494

95-
/**
96-
* @param float|int|string $amount
97-
*/
98-
public function setAmountFloatAttribute($amount): void
95+
public function setAmountFloatAttribute(float|int|string $amount): void
9996
{
10097
$math = app(MathServiceInterface::class);
10198
$decimalPlacesValue = app(CastServiceInterface::class)

0 commit comments

Comments
 (0)