From 0be5309988d05d774e4d541ddc1e4dc8b518ee1d Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Wed, 20 Apr 2022 23:22:17 +0300 Subject: [PATCH] PHP 8+ Union types --- rector.php | 4 -- src/Interfaces/Discount.php | 5 +- src/Interfaces/Exchangeable.php | 13 ++--- src/Interfaces/MaximalTaxable.php | 5 +- src/Interfaces/MinimalTaxable.php | 5 +- src/Interfaces/ProductInterface.php | 5 +- src/Interfaces/Taxable.php | 4 +- src/Interfaces/Wallet.php | 43 ++++++---------- src/Interfaces/WalletFloat.php | 48 +++++++++--------- src/Models/Transaction.php | 5 +- src/Models/Wallet.php | 5 +- src/Services/CommonServiceLegacy.php | 8 +-- src/Services/ConsistencyServiceInterface.php | 14 ++---- src/Traits/CanExchange.php | 13 ++--- src/Traits/HasWallet.php | 42 ++++++---------- src/Traits/HasWalletFloat.php | 52 +++++++++----------- tests/Infra/Models/Item.php | 2 +- tests/Infra/Models/ItemTax.php | 4 +- 18 files changed, 100 insertions(+), 177 deletions(-) diff --git a/rector.php b/rector.php index e37e6bfa8..868b562f1 100644 --- a/rector.php +++ b/rector.php @@ -18,10 +18,6 @@ __DIR__ . '/tests', ]); - $parameters->set(Option::SKIP, [ - UnionTypesRector::class - ]); - // Define what rule sets will be applied $containerConfigurator->import(PHPUnitSetList::PHPUNIT_91); $containerConfigurator->import(LaravelSetList::LARAVEL_80); diff --git a/src/Interfaces/Discount.php b/src/Interfaces/Discount.php index 3c06dd597..fc57c4846 100644 --- a/src/Interfaces/Discount.php +++ b/src/Interfaces/Discount.php @@ -6,8 +6,5 @@ interface Discount { - /** - * @return float|int - */ - public function getPersonalDiscount(Customer $customer); + public function getPersonalDiscount(Customer $customer): float|int; } diff --git a/src/Interfaces/Exchangeable.php b/src/Interfaces/Exchangeable.php index 4e60163db..b85c835d1 100644 --- a/src/Interfaces/Exchangeable.php +++ b/src/Interfaces/Exchangeable.php @@ -17,8 +17,6 @@ interface Exchangeable { /** - * @param int|string $amount - * * @throws BalanceIsEmpty * @throws InsufficientFunds * @throws LockProviderNotFoundException @@ -27,21 +25,16 @@ interface Exchangeable * @throws TransactionFailedException * @throws ExceptionInterface */ - public function exchange(Wallet $to, $amount, ExtraDtoInterface|array|null $meta = null): Transfer; + public function exchange(Wallet $to, int|string $amount, ExtraDtoInterface|array|null $meta = null): Transfer; - /** - * @param int|string $amount - */ - public function safeExchange(Wallet $to, $amount, ExtraDtoInterface|array|null $meta = null): ?Transfer; + public function safeExchange(Wallet $to, int|string $amount, ExtraDtoInterface|array|null $meta = null): ?Transfer; /** - * @param int|string $amount - * * @throws LockProviderNotFoundException * @throws RecordNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface */ - public function forceExchange(Wallet $to, $amount, ExtraDtoInterface|array|null $meta = null): Transfer; + public function forceExchange(Wallet $to, int|string $amount, ExtraDtoInterface|array|null $meta = null): Transfer; } diff --git a/src/Interfaces/MaximalTaxable.php b/src/Interfaces/MaximalTaxable.php index 4ae1495d9..c06daa052 100644 --- a/src/Interfaces/MaximalTaxable.php +++ b/src/Interfaces/MaximalTaxable.php @@ -6,8 +6,5 @@ interface MaximalTaxable extends Taxable { - /** - * @return float|int - */ - public function getMaximalFee(); + public function getMaximalFee(): float|int; } diff --git a/src/Interfaces/MinimalTaxable.php b/src/Interfaces/MinimalTaxable.php index 472af7dc2..900400c62 100644 --- a/src/Interfaces/MinimalTaxable.php +++ b/src/Interfaces/MinimalTaxable.php @@ -6,8 +6,5 @@ interface MinimalTaxable extends Taxable { - /** - * @return float|int - */ - public function getMinimalFee(); + public function getMinimalFee(): float|int; } diff --git a/src/Interfaces/ProductInterface.php b/src/Interfaces/ProductInterface.php index c471bd036..d2062231c 100644 --- a/src/Interfaces/ProductInterface.php +++ b/src/Interfaces/ProductInterface.php @@ -6,10 +6,7 @@ interface ProductInterface extends Wallet { - /** - * @return float|int|string - */ - public function getAmountProduct(Customer $customer); + public function getAmountProduct(Customer $customer): float|int|string; public function getMetaProduct(): ?array; } diff --git a/src/Interfaces/Taxable.php b/src/Interfaces/Taxable.php index e59fb0ea5..ad291d595 100644 --- a/src/Interfaces/Taxable.php +++ b/src/Interfaces/Taxable.php @@ -10,8 +10,6 @@ interface Taxable * Specify the percentage of the amount. For example, the product costs $100, the equivalent of 15%. That's $115. * * Minimum 0; Maximum 100 Example: return 7.5; // 7.5% - * - * @return float|int */ - public function getFeePercent(); + public function getFeePercent(): float|int; } diff --git a/src/Interfaces/Wallet.php b/src/Interfaces/Wallet.php index 84307de1d..cc16b307d 100644 --- a/src/Interfaces/Wallet.php +++ b/src/Interfaces/Wallet.php @@ -20,19 +20,15 @@ interface Wallet { /** - * @param int|string $amount - * * @throws AmountInvalid * @throws LockProviderNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface */ - public function deposit($amount, ?array $meta = null, bool $confirmed = true): Transaction; + public function deposit(int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction; /** - * @param int|string $amount - * * @throws AmountInvalid * @throws BalanceIsEmpty * @throws InsufficientFunds @@ -41,22 +37,18 @@ public function deposit($amount, ?array $meta = null, bool $confirmed = true): T * @throws TransactionFailedException * @throws ExceptionInterface */ - public function withdraw($amount, ?array $meta = null, bool $confirmed = true): Transaction; + public function withdraw(int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction; /** - * @param int|string $amount - * * @throws AmountInvalid * @throws LockProviderNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface */ - public function forceWithdraw($amount, ?array $meta = null, bool $confirmed = true): Transaction; + public function forceWithdraw(int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction; /** - * @param int|string $amount - * * @throws AmountInvalid * @throws BalanceIsEmpty * @throws InsufficientFunds @@ -65,33 +57,30 @@ public function forceWithdraw($amount, ?array $meta = null, bool $confirmed = tr * @throws TransactionFailedException * @throws ExceptionInterface */ - public function transfer(self $wallet, $amount, ExtraDtoInterface|array|null $meta = null): Transfer; + public function transfer(self $wallet, int|string $amount, ExtraDtoInterface|array|null $meta = null): Transfer; - /** - * @param int|string $amount - */ - public function safeTransfer(self $wallet, $amount, ExtraDtoInterface|array|null $meta = null): ?Transfer; + public function safeTransfer( + self $wallet, + int|string $amount, + ExtraDtoInterface|array|null $meta = null + ): ?Transfer; /** - * @param int|string $amount - * * @throws AmountInvalid * @throws LockProviderNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface */ - public function forceTransfer(self $wallet, $amount, ExtraDtoInterface|array|null $meta = null): Transfer; + public function forceTransfer( + self $wallet, + int|string $amount, + ExtraDtoInterface|array|null $meta = null + ): Transfer; - /** - * @param int|string $amount - */ - public function canWithdraw($amount, bool $allowZero = false): bool; + public function canWithdraw(int|string $amount, bool $allowZero = false): bool; - /** - * @return float|int - */ - public function getBalanceAttribute(); + public function getBalanceAttribute(): string; public function getBalanceIntAttribute(): int; diff --git a/src/Interfaces/WalletFloat.php b/src/Interfaces/WalletFloat.php index 0fe6ce550..6f954495c 100644 --- a/src/Interfaces/WalletFloat.php +++ b/src/Interfaces/WalletFloat.php @@ -18,19 +18,15 @@ interface WalletFloat { /** - * @param float|string $amount - * * @throws AmountInvalid * @throws LockProviderNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface */ - public function depositFloat($amount, ?array $meta = null, bool $confirmed = true): Transaction; + public function depositFloat(float|int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction; /** - * @param float|string $amount - * * @throws AmountInvalid * @throws BalanceIsEmpty * @throws InsufficientFunds @@ -39,22 +35,22 @@ public function depositFloat($amount, ?array $meta = null, bool $confirmed = tru * @throws TransactionFailedException * @throws ExceptionInterface */ - public function withdrawFloat($amount, ?array $meta = null, bool $confirmed = true): Transaction; + public function withdrawFloat(float|int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction; /** - * @param float|string $amount - * * @throws AmountInvalid * @throws LockProviderNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface */ - public function forceWithdrawFloat($amount, ?array $meta = null, bool $confirmed = true): Transaction; + public function forceWithdrawFloat( + float|int|string $amount, + ?array $meta = null, + bool $confirmed = true + ): Transaction; /** - * @param float|string $amount - * * @throws AmountInvalid * @throws BalanceIsEmpty * @throws InsufficientFunds @@ -63,31 +59,35 @@ public function forceWithdrawFloat($amount, ?array $meta = null, bool $confirmed * @throws TransactionFailedException * @throws ExceptionInterface */ - public function transferFloat(Wallet $wallet, $amount, ExtraDtoInterface|array|null $meta = null): Transfer; + public function transferFloat( + Wallet $wallet, + float|int|string $amount, + ExtraDtoInterface|array|null $meta = null + ): Transfer; - /** - * @param float|string $amount - */ - public function safeTransferFloat(Wallet $wallet, $amount, ExtraDtoInterface|array|null $meta = null): ?Transfer; + public function safeTransferFloat( + Wallet $wallet, + float|int|string $amount, + ExtraDtoInterface|array|null $meta = null + ): ?Transfer; /** - * @param float|string $amount - * * @throws AmountInvalid * @throws LockProviderNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface */ - public function forceTransferFloat(Wallet $wallet, $amount, ExtraDtoInterface|array|null $meta = null): Transfer; + public function forceTransferFloat( + Wallet $wallet, + float|int|string $amount, + ExtraDtoInterface|array|null $meta = null + ): Transfer; - /** - * @param float|string $amount - */ - public function canWithdrawFloat($amount): bool; + public function canWithdrawFloat(float|int|string $amount): bool; /** - * @return float|int|string + * @return string */ public function getBalanceFloatAttribute(); } diff --git a/src/Models/Transaction.php b/src/Models/Transaction.php index f2f88a4b5..7726eaba8 100644 --- a/src/Models/Transaction.php +++ b/src/Models/Transaction.php @@ -92,10 +92,7 @@ public function getAmountFloatAttribute(): string return $math->div($this->amount, $decimalPlaces); } - /** - * @param float|int|string $amount - */ - public function setAmountFloatAttribute($amount): void + public function setAmountFloatAttribute(float|int|string $amount): void { $math = app(MathServiceInterface::class); $decimalPlacesValue = app(CastServiceInterface::class) diff --git a/src/Models/Wallet.php b/src/Models/Wallet.php index 5f4163433..7f8938b48 100644 --- a/src/Models/Wallet.php +++ b/src/Models/Wallet.php @@ -124,10 +124,7 @@ public function getOriginalBalanceAttribute(): string return (string) $this->getRawOriginal('balance', 0); } - /** - * @return float|int|string - */ - public function getAvailableBalanceAttribute() + public function getAvailableBalanceAttribute(): float|int|string { return $this->walletTransactions() ->where('confirmed', true) diff --git a/src/Services/CommonServiceLegacy.php b/src/Services/CommonServiceLegacy.php index 9ddaf86c1..c15ac1b28 100644 --- a/src/Services/CommonServiceLegacy.php +++ b/src/Services/CommonServiceLegacy.php @@ -33,8 +33,6 @@ public function __construct( } /** - * @param int|string $amount - * * @throws LockProviderNotFoundException * @throws RecordNotFoundException * @throws RecordsNotFoundException @@ -44,7 +42,7 @@ public function __construct( public function forceTransfer( Wallet $from, Wallet $to, - $amount, + int|string $amount, ExtraDtoInterface|array|null $meta = null, string $status = Transfer::STATUS_TRANSFER ): Transfer { @@ -119,15 +117,13 @@ public function applyTransfers(array $objects): array } /** - * @param float|int|string $amount - * * @throws LockProviderNotFoundException * @throws RecordNotFoundException */ public function makeTransaction( Wallet $wallet, string $type, - $amount, + float|int|string $amount, ?array $meta, bool $confirmed = true ): Transaction { diff --git a/src/Services/ConsistencyServiceInterface.php b/src/Services/ConsistencyServiceInterface.php index e6b9aa127..8ae66c519 100644 --- a/src/Services/ConsistencyServiceInterface.php +++ b/src/Services/ConsistencyServiceInterface.php @@ -13,25 +13,17 @@ interface ConsistencyServiceInterface { /** - * @param float|int|string $amount - * * @throws AmountInvalid */ - public function checkPositive($amount): void; + public function checkPositive(float|int|string $amount): void; /** - * @param float|int|string $amount - * * @throws BalanceIsEmpty * @throws InsufficientFunds */ - public function checkPotential(Wallet $object, $amount, bool $allowZero = false): void; + public function checkPotential(Wallet $object, float|int|string $amount, bool $allowZero = false): void; - /** - * @param float|int|string $balance - * @param float|int|string $amount - */ - public function canWithdraw($balance, $amount, bool $allowZero = false): bool; + public function canWithdraw(int|string $balance, int|string $amount, bool $allowZero = false): bool; /** * @param TransferLazyDtoInterface[] $objects diff --git a/src/Traits/CanExchange.php b/src/Traits/CanExchange.php index dbc2bfd83..270c27066 100644 --- a/src/Traits/CanExchange.php +++ b/src/Traits/CanExchange.php @@ -31,8 +31,6 @@ trait CanExchange { /** - * @param int|string $amount - * * @throws BalanceIsEmpty * @throws InsufficientFunds * @throws LockProviderNotFoundException @@ -41,7 +39,7 @@ trait CanExchange * @throws TransactionFailedException * @throws ExceptionInterface */ - public function exchange(Wallet $to, $amount, ExtraDtoInterface|array|null $meta = null): Transfer + public function exchange(Wallet $to, int|string $amount, ExtraDtoInterface|array|null $meta = null): Transfer { $wallet = app(CastServiceInterface::class)->getWallet($this); @@ -50,10 +48,7 @@ public function exchange(Wallet $to, $amount, ExtraDtoInterface|array|null $meta return $this->forceExchange($to, $amount, $meta); } - /** - * @param int|string $amount - */ - public function safeExchange(Wallet $to, $amount, ExtraDtoInterface|array|null $meta = null): ?Transfer + public function safeExchange(Wallet $to, int|string $amount, ExtraDtoInterface|array|null $meta = null): ?Transfer { try { return $this->exchange($to, $amount, $meta); @@ -63,15 +58,13 @@ public function safeExchange(Wallet $to, $amount, ExtraDtoInterface|array|null $ } /** - * @param int|string $amount - * * @throws LockProviderNotFoundException * @throws RecordNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface */ - public function forceExchange(Wallet $to, $amount, ExtraDtoInterface|array|null $meta = null): Transfer + public function forceExchange(Wallet $to, int|string $amount, ExtraDtoInterface|array|null $meta = null): Transfer { return app(AtomicServiceInterface::class)->block($this, function () use ($to, $amount, $meta) { $extraAssembler = app(ExtraDtoAssemblerInterface::class); diff --git a/src/Traits/HasWallet.php b/src/Traits/HasWallet.php index 3fe5c9162..fda3b728a 100644 --- a/src/Traits/HasWallet.php +++ b/src/Traits/HasWallet.php @@ -44,15 +44,13 @@ trait HasWallet /** * The input means in the system. * - * @param int|string $amount - * * @throws AmountInvalid * @throws LockProviderNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface */ - public function deposit($amount, ?array $meta = null, bool $confirmed = true): Transaction + public function deposit(int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction { return app(AtomicServiceInterface::class)->block( $this, @@ -63,10 +61,8 @@ public function deposit($amount, ?array $meta = null, bool $confirmed = true): T /** * Magic laravel framework method, makes it possible to call property balance. - * - * @return float|int|string */ - public function getBalanceAttribute() + public function getBalanceAttribute(): string { /** @var Wallet $this */ return app(RegulatorServiceInterface::class)->amount(app(CastServiceInterface::class)->getWallet($this)); @@ -101,11 +97,12 @@ public function transactions(): MorphMany /** * This method ignores errors that occur when transferring funds. - * - * @param int|string $amount */ - public function safeTransfer(Wallet $wallet, $amount, ExtraDtoInterface|array|null $meta = null): ?Transfer - { + public function safeTransfer( + Wallet $wallet, + int|string $amount, + ExtraDtoInterface|array|null $meta = null + ): ?Transfer { try { return $this->transfer($wallet, $amount, $meta); } catch (ExceptionInterface) { @@ -116,8 +113,6 @@ public function safeTransfer(Wallet $wallet, $amount, ExtraDtoInterface|array|nu /** * A method that transfers funds from host to host. * - * @param int|string $amount - * * @throws AmountInvalid * @throws BalanceIsEmpty * @throws InsufficientFunds @@ -126,7 +121,7 @@ public function safeTransfer(Wallet $wallet, $amount, ExtraDtoInterface|array|nu * @throws TransactionFailedException * @throws ExceptionInterface */ - public function transfer(Wallet $wallet, $amount, ExtraDtoInterface|array|null $meta = null): Transfer + public function transfer(Wallet $wallet, int|string $amount, ExtraDtoInterface|array|null $meta = null): Transfer { /** @var Wallet $this */ app(ConsistencyServiceInterface::class)->checkPotential($this, $amount); @@ -137,8 +132,6 @@ public function transfer(Wallet $wallet, $amount, ExtraDtoInterface|array|null $ /** * Withdrawals from the system. * - * @param int|string $amount - * * @throws AmountInvalid * @throws BalanceIsEmpty * @throws InsufficientFunds @@ -147,7 +140,7 @@ public function transfer(Wallet $wallet, $amount, ExtraDtoInterface|array|null $ * @throws TransactionFailedException * @throws ExceptionInterface */ - public function withdraw($amount, ?array $meta = null, bool $confirmed = true): Transaction + public function withdraw(int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction { /** @var Wallet $this */ app(ConsistencyServiceInterface::class)->checkPotential($this, $amount); @@ -157,10 +150,8 @@ public function withdraw($amount, ?array $meta = null, bool $confirmed = true): /** * Checks if you can withdraw funds. - * - * @param float|int|string $amount */ - public function canWithdraw($amount, bool $allowZero = false): bool + public function canWithdraw(int|string $amount, bool $allowZero = false): bool { $mathService = app(MathServiceInterface::class); $wallet = app(CastServiceInterface::class)->getWallet($this); @@ -172,8 +163,6 @@ public function canWithdraw($amount, bool $allowZero = false): bool /** * Forced to withdraw funds from system. * - * @param int|string $amount - * * @throws AmountInvalid * @throws LockProviderNotFoundException * @throws RecordsNotFoundException @@ -181,7 +170,7 @@ public function canWithdraw($amount, bool $allowZero = false): bool * @throws ExceptionInterface */ public function forceWithdraw( - $amount, + int|string $amount, ExtraDtoInterface|array|null $meta = null, bool $confirmed = true ): Transaction { @@ -196,16 +185,17 @@ public function forceWithdraw( * the forced transfer is needed when the user does not have the money, and we drive it. Sometimes you do. Depends * on business logic. * - * @param int|string $amount - * * @throws AmountInvalid * @throws LockProviderNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface */ - public function forceTransfer(Wallet $wallet, $amount, ExtraDtoInterface|array|null $meta = null): Transfer - { + public function forceTransfer( + Wallet $wallet, + int|string $amount, + ExtraDtoInterface|array|null $meta = null + ): Transfer { return app(AtomicServiceInterface::class)->block( $this, fn () => app(CommonServiceLegacy::class) diff --git a/src/Traits/HasWalletFloat.php b/src/Traits/HasWalletFloat.php index d2188fc92..97d5e1ab0 100644 --- a/src/Traits/HasWalletFloat.php +++ b/src/Traits/HasWalletFloat.php @@ -30,16 +30,17 @@ trait HasWalletFloat use HasWallet; /** - * @param float|string $amount - * * @throws AmountInvalid * @throws LockProviderNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface */ - public function forceWithdrawFloat($amount, ?array $meta = null, bool $confirmed = true): Transaction - { + public function forceWithdrawFloat( + float|int|string $amount, + ?array $meta = null, + bool $confirmed = true + ): Transaction { $math = app(MathServiceInterface::class); $decimalPlacesValue = app(CastServiceInterface::class)->getWallet($this)->decimal_places; $decimalPlaces = $math->powTen($decimalPlacesValue); @@ -49,15 +50,13 @@ public function forceWithdrawFloat($amount, ?array $meta = null, bool $confirmed } /** - * @param float|string $amount - * * @throws AmountInvalid * @throws LockProviderNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface */ - public function depositFloat($amount, ?array $meta = null, bool $confirmed = true): Transaction + public function depositFloat(float|int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction { $math = app(MathServiceInterface::class); $decimalPlacesValue = app(CastServiceInterface::class)->getWallet($this)->decimal_places; @@ -68,8 +67,6 @@ public function depositFloat($amount, ?array $meta = null, bool $confirmed = tru } /** - * @param float|string $amount - * * @throws AmountInvalid * @throws BalanceIsEmpty * @throws InsufficientFunds @@ -78,7 +75,7 @@ public function depositFloat($amount, ?array $meta = null, bool $confirmed = tru * @throws TransactionFailedException * @throws ExceptionInterface */ - public function withdrawFloat($amount, ?array $meta = null, bool $confirmed = true): Transaction + public function withdrawFloat(float|int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction { $math = app(MathServiceInterface::class); $decimalPlacesValue = app(CastServiceInterface::class)->getWallet($this)->decimal_places; @@ -88,10 +85,7 @@ public function withdrawFloat($amount, ?array $meta = null, bool $confirmed = tr return $this->withdraw($result, $meta, $confirmed); } - /** - * @param float|string $amount - */ - public function canWithdrawFloat($amount): bool + public function canWithdrawFloat(float|int|string $amount): bool { $math = app(MathServiceInterface::class); $decimalPlacesValue = app(CastServiceInterface::class)->getWallet($this)->decimal_places; @@ -102,8 +96,6 @@ public function canWithdrawFloat($amount): bool } /** - * @param float|string $amount - * * @throws AmountInvalid * @throws BalanceIsEmpty * @throws InsufficientFunds @@ -112,8 +104,11 @@ public function canWithdrawFloat($amount): bool * @throws TransactionFailedException * @throws ExceptionInterface */ - public function transferFloat(Wallet $wallet, $amount, ExtraDtoInterface|array|null $meta = null): Transfer - { + public function transferFloat( + Wallet $wallet, + float|int|string $amount, + ExtraDtoInterface|array|null $meta = null + ): Transfer { $math = app(MathServiceInterface::class); $decimalPlacesValue = app(CastServiceInterface::class)->getWallet($this)->decimal_places; $decimalPlaces = $math->powTen($decimalPlacesValue); @@ -122,11 +117,11 @@ public function transferFloat(Wallet $wallet, $amount, ExtraDtoInterface|array|n return $this->transfer($wallet, $result, $meta); } - /** - * @param float|string $amount - */ - public function safeTransferFloat(Wallet $wallet, $amount, ExtraDtoInterface|array|null $meta = null): ?Transfer - { + public function safeTransferFloat( + Wallet $wallet, + float|int|string $amount, + ExtraDtoInterface|array|null $meta = null + ): ?Transfer { $math = app(MathServiceInterface::class); $decimalPlacesValue = app(CastServiceInterface::class)->getWallet($this)->decimal_places; $decimalPlaces = $math->powTen($decimalPlacesValue); @@ -136,16 +131,17 @@ public function safeTransferFloat(Wallet $wallet, $amount, ExtraDtoInterface|arr } /** - * @param float|string $amount - * * @throws AmountInvalid * @throws LockProviderNotFoundException * @throws RecordsNotFoundException * @throws TransactionFailedException * @throws ExceptionInterface */ - public function forceTransferFloat(Wallet $wallet, $amount, ExtraDtoInterface|array|null $meta = null): Transfer - { + public function forceTransferFloat( + Wallet $wallet, + float|int|string $amount, + ExtraDtoInterface|array|null $meta = null + ): Transfer { $math = app(MathServiceInterface::class); $decimalPlacesValue = app(CastServiceInterface::class)->getWallet($this)->decimal_places; $decimalPlaces = $math->powTen($decimalPlacesValue); @@ -155,7 +151,7 @@ public function forceTransferFloat(Wallet $wallet, $amount, ExtraDtoInterface|ar } /** - * @return float|int|string + * @return string */ public function getBalanceFloatAttribute() { diff --git a/tests/Infra/Models/Item.php b/tests/Infra/Models/Item.php index f35534564..260601cdc 100644 --- a/tests/Infra/Models/Item.php +++ b/tests/Infra/Models/Item.php @@ -37,7 +37,7 @@ public function canBuy(Customer $customer, int $quantity = 1, bool $force = fals return $result && !$customer->paid($this); } - public function getAmountProduct(Customer $customer) + public function getAmountProduct(Customer $customer): float|int|string { /** @var Wallet $wallet */ $wallet = app(CastService::class)->getWallet($customer); diff --git a/tests/Infra/Models/ItemTax.php b/tests/Infra/Models/ItemTax.php index fe74e6d23..ffb6efa79 100644 --- a/tests/Infra/Models/ItemTax.php +++ b/tests/Infra/Models/ItemTax.php @@ -17,10 +17,8 @@ public function getTable(): string * Specify the percentage of the amount. For example, the product costs $100, the equivalent of 15%. That's $115. * * Minimum 0; Maximum 100 Example: return 7.5; // 7.5% - * - * @return float|int */ - public function getFeePercent() + public function getFeePercent(): float|int { return 7.5; }