Skip to content

Commit 22046a8

Browse files
committed
Refactor PHPDoc comments and improve type hints across multiple interfaces and models
- Removed redundant PHPDoc comments in the Confirmable and ProductLimitedInterface interfaces. - Updated PHPDoc comments to include type hints for return values in various DTOs and services. - Enhanced type safety by specifying generic types in relationships within the Wallet model and related traits. - Cleaned up unused comments and improved clarity in method signatures across several classes. - Ensured consistency in type declarations and added assertions where necessary for better code quality.
1 parent 77ea7a6 commit 22046a8

35 files changed

+459
-950
lines changed

phpstan.src.baseline.neon

Lines changed: 15 additions & 393 deletions
Large diffs are not rendered by default.

src/Interfaces/Confirmable.php

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@
1818
interface Confirmable
1919
{
2020
/**
21-
* Confirm the transaction.
22-
*
23-
* This method confirms the given transaction if it is not already confirmed.
24-
*
25-
* @param Transaction $transaction The transaction to confirm.
26-
* @return bool Returns true if the transaction was confirmed, false otherwise.
27-
*
2821
* @throws BalanceIsEmpty If the balance is empty.
2922
* @throws InsufficientFunds If there are insufficient funds.
3023
* @throws ConfirmedInvalid If the transaction is already confirmed.
@@ -37,15 +30,6 @@ interface Confirmable
3730
public function confirm(Transaction $transaction): bool;
3831

3932
/**
40-
* Safely confirms the transaction.
41-
*
42-
* This method attempts to confirm the given transaction. If an exception occurs during the confirmation process,
43-
* it will be caught and handled. If the confirmation is successful, true will be returned. If an exception occurs,
44-
* false will be returned.
45-
*
46-
* @param Transaction $transaction The transaction to confirm.
47-
* @return bool Returns true if the transaction was confirmed, false otherwise.
48-
*
4933
* @throws BalanceIsEmpty If the balance is empty.
5034
* @throws InsufficientFunds If there are insufficient funds.
5135
* @throws ConfirmedInvalid If the transaction is already confirmed.
@@ -58,16 +42,6 @@ public function confirm(Transaction $transaction): bool;
5842
public function safeConfirm(Transaction $transaction): bool;
5943

6044
/**
61-
* Reset the confirmation of the transaction.
62-
*
63-
* This method is used to remove the confirmation from a transaction.
64-
* If the transaction is already confirmed, a `ConfirmedInvalid` exception will be thrown.
65-
* If the transaction does not belong to the wallet, a `WalletOwnerInvalid` exception will be thrown.
66-
* If the transaction was not found, a `RecordNotFoundException` will be thrown.
67-
*
68-
* @param Transaction $transaction The transaction to reset.
69-
* @return bool Returns true if the confirmation was reset, false otherwise.
70-
*
7145
* @throws UnconfirmedInvalid If the transaction is not confirmed.
7246
* @throws WalletOwnerInvalid If the transaction does not belong to the wallet.
7347
* @throws RecordNotFoundException If the transaction was not found.
@@ -77,30 +51,9 @@ public function safeConfirm(Transaction $transaction): bool;
7751
*/
7852
public function resetConfirm(Transaction $transaction): bool;
7953

80-
/**
81-
* Safely reset the confirmation of the transaction.
82-
*
83-
* This method is used to remove the confirmation from a transaction.
84-
* If the transaction is already confirmed, the confirmation will be reset.
85-
* If the transaction does not belong to the wallet, a `WalletOwnerInvalid` exception will be thrown.
86-
* If the transaction was not found, a `RecordNotFoundException` will be thrown.
87-
*
88-
* @param Transaction $transaction The transaction to reset.
89-
* @return bool Returns true if the confirmation was reset, false otherwise.
90-
*/
9154
public function safeResetConfirm(Transaction $transaction): bool;
9255

9356
/**
94-
* Force confirm the transaction.
95-
*
96-
* This method forces the confirmation of the given transaction even if it is already confirmed.
97-
* If the transaction is already confirmed, a `ConfirmedInvalid` exception will be thrown.
98-
* If the transaction does not belong to the wallet, a `WalletOwnerInvalid` exception will be thrown.
99-
* If the transaction was not found, a `RecordNotFoundException` will be thrown.
100-
*
101-
* @param Transaction $transaction The transaction to confirm.
102-
* @return bool Returns true if the transaction was confirmed, false otherwise.
103-
*
10457
* @throws ConfirmedInvalid If the transaction is already confirmed.
10558
* @throws WalletOwnerInvalid If the transaction does not belong to the wallet.
10659
* @throws RecordNotFoundException If the transaction was not found.

src/Interfaces/ProductLimitedInterface.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,5 @@
66

77
interface ProductLimitedInterface extends ProductInterface
88
{
9-
/**
10-
* Check if the customer can buy the product.
11-
*
12-
* @param Customer $customer The customer entity
13-
* @param int $quantity The quantity of the product to buy. Default is 1.
14-
* @param bool $force Flag to force the purchase. Default is false.
15-
* @return bool Returns true if the customer can buy the product, false otherwise.
16-
*
17-
* The method checks if the customer can buy the product based on the quantity and the force flag.
18-
* If the force flag is set to true, the method returns true regardless of the quantity.
19-
* If the force flag is set to false, the method returns true if the quantity of the product is
20-
* greater than or equal to the quantity to buy.
21-
*
22-
* The method does not check if the customer has already bought the product. It is the responsibility
23-
* of the caller to check if the customer has already bought the product.
24-
*/
259
public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool;
2610
}

src/Interfaces/Wallet.php

Lines changed: 19 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@
1212
use Bavix\Wallet\Internal\Exceptions\TransactionFailedException;
1313
use Bavix\Wallet\Models\Transaction;
1414
use Bavix\Wallet\Models\Transfer;
15+
use Illuminate\Database\Eloquent\Model;
1516
use Illuminate\Database\Eloquent\Relations\HasMany;
1617
use Illuminate\Database\Eloquent\Relations\MorphMany;
1718
use Illuminate\Database\RecordsNotFoundException;
1819

1920
interface Wallet
2021
{
2122
/**
22-
* Deposit the specified amount of money into the wallet.
23-
*
24-
* @param int|non-empty-string $amount The amount to deposit.
25-
* @param array<mixed>|null $meta Additional information for the transaction.
26-
* @param bool $confirmed Whether the transaction is confirmed or not.
27-
* @return Transaction The created transaction.
23+
* @param int|non-empty-string $amount
24+
* @param array<mixed>|null $meta
2825
*
2926
* @throws AmountInvalid If the amount is invalid.
3027
* @throws RecordsNotFoundException If the wallet is not found.
@@ -34,12 +31,8 @@ interface Wallet
3431
public function deposit(int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction;
3532

3633
/**
37-
* Withdraw the specified amount of money from the wallet.
38-
*
39-
* @param int|non-empty-string $amount The amount to withdraw.
40-
* @param array<mixed>|null $meta Additional information for the transaction.
41-
* @param bool $confirmed Whether the transaction is confirmed or not.
42-
* @return Transaction The created transaction.
34+
* @param int|non-empty-string $amount
35+
* @param array<mixed>|null $meta
4336
*
4437
* @throws AmountInvalid If the amount is invalid.
4538
* @throws BalanceIsEmpty If the balance is empty.
@@ -51,12 +44,8 @@ public function deposit(int|string $amount, ?array $meta = null, bool $confirmed
5144
public function withdraw(int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction;
5245

5346
/**
54-
* Forced to withdraw funds from the wallet.
55-
*
56-
* @param int|non-empty-string $amount The amount to withdraw.
57-
* @param array<mixed>|null $meta Additional information for the transaction.
58-
* @param bool $confirmed Whether the transaction is confirmed or not.
59-
* @return Transaction The created transaction.
47+
* @param int|non-empty-string $amount
48+
* @param array<mixed>|null $meta
6049
*
6150
* @throws AmountInvalid If the amount is invalid.
6251
* @throws RecordsNotFoundException If the wallet is not found.
@@ -66,12 +55,8 @@ public function withdraw(int|string $amount, ?array $meta = null, bool $confirme
6655
public function forceWithdraw(int|string $amount, ?array $meta = null, bool $confirmed = true): Transaction;
6756

6857
/**
69-
* Transfer funds from this wallet to another.
70-
*
71-
* @param self $wallet The wallet to transfer funds to.
72-
* @param int|non-empty-string $amount The amount to transfer.
73-
* @param ExtraDtoInterface|array<mixed>|null $meta Additional information for the transaction.
74-
* @return Transfer The created transaction.
58+
* @param int|non-empty-string $amount
59+
* @param ExtraDtoInterface|array<mixed>|null $meta
7560
*
7661
* @throws AmountInvalid If the amount is invalid.
7762
* @throws BalanceIsEmpty If the balance is empty.
@@ -83,17 +68,8 @@ public function forceWithdraw(int|string $amount, ?array $meta = null, bool $con
8368
public function transfer(self $wallet, int|string $amount, ExtraDtoInterface|array|null $meta = null): Transfer;
8469

8570
/**
86-
* Safely transfers funds from this wallet to another.
87-
*
88-
* This method attempts to transfer funds from this wallet to another wallet.
89-
* If an error occurs during the process, null is returned.
90-
*
91-
* @param self $wallet The wallet to transfer funds to.
92-
* @param int|non-empty-string $amount The amount to transfer.
93-
* @param ExtraDtoInterface|array<mixed>|null $meta Additional information for the transaction.
94-
* This can be an instance of an ExtraDtoInterface
95-
* or an array of arbitrary data.
96-
* @return null|Transfer The created transaction, or null if an error occurred.
71+
* @param int|non-empty-string $amount
72+
* @param ExtraDtoInterface|array<mixed>|null $meta
9773
*
9874
* @throws AmountInvalid If the amount is invalid.
9975
* @throws BalanceIsEmpty If the balance is empty.
@@ -109,18 +85,8 @@ public function safeTransfer(
10985
): ?Transfer;
11086

11187
/**
112-
* Forces a transfer of funds from this wallet to another, bypassing certain safety checks.
113-
*
114-
* This method is intended for use in scenarios where a transfer must be completed regardless of
115-
* the usual validation checks (e.g., sufficient funds, wallet status). It is critical to use this
116-
* method with caution as it can result in negative balances or other unintended consequences.
117-
*
118-
* @param self $wallet The wallet instance to which funds will be transferred.
119-
* @param int|non-empty-string $amount The amount of funds to transfer. Can be specified as an integer or a string.
120-
* @param ExtraDtoInterface|array<mixed>|null $meta Additional metadata associated with the transfer. This
121-
* can be used to store extra information about the transaction, such as reasons for the transfer or
122-
* identifiers linking to other systems.
123-
* @return Transfer Returns a Transfer object representing the completed transaction.
88+
* @param int|non-empty-string $amount
89+
* @param ExtraDtoInterface|array<mixed>|null $meta
12490
*
12591
* @throws AmountInvalid If the amount specified is invalid (e.g., negative values).
12692
* @throws RecordsNotFoundException If the target wallet cannot be found.
@@ -136,60 +102,34 @@ public function forceTransfer(
136102
): Transfer;
137103

138104
/**
139-
* Checks if the wallet can safely withdraw the specified amount.
140-
*
141-
* @param int|non-empty-string $amount The amount to withdraw.
142-
* @param bool $allowZero Whether to allow withdrawing when the balance is zero.
143-
* @return bool Returns true if the wallet can withdraw the specified amount, false otherwise.
105+
* @param int|non-empty-string $amount
144106
*/
145107
public function canWithdraw(int|string $amount, bool $allowZero = false): bool;
146108

147109
/**
148-
* Returns the balance of the wallet as a string.
149-
*
150-
* The balance is the total amount of funds held by the wallet.
151-
*
152-
* @return non-empty-string The balance of the wallet.
110+
* @return non-empty-string
153111
*/
154112
public function getBalanceAttribute(): string;
155113

156-
/**
157-
* Returns the balance of the wallet as an integer.
158-
*
159-
* @return int The balance of the wallet. This value is the result of
160-
* {@see getBalanceAttribute()} converted to an integer.
161-
*/
162114
public function getBalanceIntAttribute(): int;
163115

164116
/**
165-
* Represents a relationship where a wallet has many transactions.
166-
*
167-
* @return HasMany<Transaction> A collection of transactions associated with this wallet.
117+
* @return HasMany<Transaction, self>
168118
*/
169119
public function walletTransactions(): HasMany;
170120

171121
/**
172-
* Returns all the transactions associated with this wallet.
173-
*
174-
* This method returns a morph many relationship that represents all the transactions
175-
* associated with this wallet. The transactions may be of different types, such as
176-
* deposits, withdrawals, or transfers.
177-
*
178-
* @return MorphMany<Transaction> A collection of transactions associated with this wallet.
122+
* @return MorphMany<Transaction, Model>
179123
*/
180124
public function transactions(): MorphMany;
181125

182126
/**
183-
* Returns all the transfers sent by this wallet.
184-
*
185-
* @return HasMany<Transfer> A collection of transfers sent by this wallet.
127+
* @return HasMany<Transfer, self>
186128
*/
187129
public function transfers(): HasMany;
188130

189131
/**
190-
* Returns all the transfers received by this wallet.
191-
*
192-
* @return HasMany<Transfer> A collection of transfers received by this wallet.
132+
* @return HasMany<Transfer, self>
193133
*/
194134
public function receivedTransfers(): HasMany;
195135
}

0 commit comments

Comments
 (0)