Skip to content

Commit

Permalink
PHP 8+ Union types
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed May 2, 2022
1 parent 725715a commit 0be5309
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 177 deletions.
4 changes: 0 additions & 4 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions src/Interfaces/Discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

interface Discount
{
/**
* @return float|int
*/
public function getPersonalDiscount(Customer $customer);
public function getPersonalDiscount(Customer $customer): float|int;
}
13 changes: 3 additions & 10 deletions src/Interfaces/Exchangeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
interface Exchangeable
{
/**
* @param int|string $amount
*
* @throws BalanceIsEmpty
* @throws InsufficientFunds
* @throws LockProviderNotFoundException
Expand All @@ -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;
}
5 changes: 1 addition & 4 deletions src/Interfaces/MaximalTaxable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

interface MaximalTaxable extends Taxable
{
/**
* @return float|int
*/
public function getMaximalFee();
public function getMaximalFee(): float|int;
}
5 changes: 1 addition & 4 deletions src/Interfaces/MinimalTaxable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

interface MinimalTaxable extends Taxable
{
/**
* @return float|int
*/
public function getMinimalFee();
public function getMinimalFee(): float|int;
}
5 changes: 1 addition & 4 deletions src/Interfaces/ProductInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 1 addition & 3 deletions src/Interfaces/Taxable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
43 changes: 16 additions & 27 deletions src/Interfaces/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;

Expand Down
48 changes: 24 additions & 24 deletions src/Interfaces/WalletFloat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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();
}
5 changes: 1 addition & 4 deletions src/Models/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions src/Models/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions src/Services/CommonServiceLegacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public function __construct(
}

/**
* @param int|string $amount
*
* @throws LockProviderNotFoundException
* @throws RecordNotFoundException
* @throws RecordsNotFoundException
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 3 additions & 11 deletions src/Services/ConsistencyServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 0be5309

Please sign in to comment.