Skip to content

Commit

Permalink
update phpdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Jul 23, 2024
1 parent 557053c commit 61a1883
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 42 deletions.
98 changes: 74 additions & 24 deletions phpstan.src.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,64 @@ parameters:
path: src/Internal/Assembler/TransferDtoAssembler.php

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Decorator\\\\StorageServiceLockDecorator\\:\\:multiGet\\(\\) should return non\\-empty\\-array\\<non\\-empty\\-string, non\\-empty\\-string\\> but returns non\\-empty\\-array\\<non\\-empty\\-string, string\\>\\.$#"
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Decorator\\\\StorageServiceLockDecorator\\:\\:multiIncrease\\(\\) should return non\\-empty\\-array\\<non\\-empty\\-string, non\\-empty\\-string\\> but returns non\\-empty\\-array\\<string, string\\>\\.$#"
count: 1
path: src/Internal/Decorator/StorageServiceLockDecorator.php

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Decorator\\\\StorageServiceLockDecorator\\:\\:multiIncrease\\(\\) should return non\\-empty\\-array\\<non\\-empty\\-string, non\\-empty\\-string\\> but returns non\\-empty\\-array\\<string, string\\>\\.$#"
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\ItemDto\\:\\:getPricePerItem\\(\\) should return int\\|non\\-empty\\-string\\|null but returns int\\|string\\|null\\.$#"
count: 1
path: src/Internal/Decorator/StorageServiceLockDecorator.php
path: src/Internal/Dto/ItemDto.php

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransactionDto\\:\\:getAmount\\(\\) should return float\\|int\\|non\\-empty\\-string but returns float\\|int\\|string\\.$#"
count: 1
path: src/Internal/Dto/TransactionDto.php

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransactionDto\\:\\:getPayableType\\(\\) should return class\\-string but returns string\\.$#"
count: 1
path: src/Internal/Dto/TransactionDto.php

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransactionDto\\:\\:getUuid\\(\\) should return non\\-empty\\-string but returns string\\.$#"
count: 1
path: src/Internal/Dto/TransactionDto.php

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransferDto\\:\\:getFee\\(\\) should return non\\-empty\\-string but returns string\\.$#"
count: 1
path: src/Internal/Dto/TransferDto.php

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransferDto\\:\\:getUuid\\(\\) should return non\\-empty\\-string but returns string\\.$#"
count: 1
path: src/Internal/Dto/TransferDto.php

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransferLazyDto\\:\\:getFee\\(\\) should return non\\-empty\\-string but returns string\\.$#"
count: 1
path: src/Internal/Dto/TransferLazyDto.php

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransferLazyDto\\:\\:getUuid\\(\\) should return non\\-empty\\-string\\|null but returns string\\|null\\.$#"
count: 1
path: src/Internal/Dto/TransferLazyDto.php

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Events\\\\BalanceUpdatedEvent\\:\\:getBalance\\(\\) should return non\\-empty\\-string but returns string\\.$#"
count: 1
path: src/Internal/Events/BalanceUpdatedEvent.php

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Events\\\\BalanceUpdatedEvent\\:\\:getWalletUuid\\(\\) should return non\\-empty\\-string but returns string\\.$#"
count: 1
path: src/Internal/Events/BalanceUpdatedEvent.php

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Events\\\\WalletCreatedEvent\\:\\:getWalletUuid\\(\\) should return non\\-empty\\-string but returns string\\.$#"
count: 1
path: src/Internal/Events/WalletCreatedEvent.php

-
message: "#^Parameter \\#1 \\$name of method Illuminate\\\\Database\\\\ConnectionResolverInterface\\:\\:connection\\(\\) expects string\\|null, mixed given\\.$#"
Expand Down Expand Up @@ -106,7 +156,12 @@ parameters:
path: src/Internal/Service/MathService.php

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Service\\\\StateService\\:\\:get\\(\\) should return string\\|null but returns mixed\\.$#"
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Service\\\\StateService\\:\\:get\\(\\) should return non\\-empty\\-string\\|null but returns mixed\\.$#"
count: 1
path: src/Internal/Service/StateService.php

-
message: "#^Method Bavix\\\\Wallet\\\\Internal\\\\Service\\\\StateService\\:\\:get\\(\\) should return non\\-empty\\-string\\|null but returns string\\|null\\.$#"
count: 1
path: src/Internal/Service/StateService.php

Expand Down Expand Up @@ -250,11 +305,6 @@ parameters:
count: 1
path: src/Models/Wallet.php

-
message: "#^Parameter \\#1 \\$first of method Bavix\\\\Wallet\\\\Internal\\\\Service\\\\MathService\\:\\:sub\\(\\) expects float\\|int\\|non\\-empty\\-string, int\\|string given\\.$#"
count: 1
path: src/Models/Wallet.php

-
message: "#^Parameter \\#1 \\$related of method Illuminate\\\\Database\\\\Eloquent\\\\Model\\:\\:hasMany\\(\\) expects class\\-string\\<Illuminate\\\\Database\\\\Eloquent\\\\Model\\>, mixed given\\.$#"
count: 6
Expand Down Expand Up @@ -310,21 +360,11 @@ parameters:
count: 2
path: src/Models/Wallet.php

-
message: "#^Parameter \\#2 \\$second of method Bavix\\\\Wallet\\\\Internal\\\\Service\\\\MathServiceInterface\\:\\:mul\\(\\) expects float\\|int\\|non\\-empty\\-string, int\\|string given\\.$#"
count: 1
path: src/Objects/Cart.php

-
message: "#^Parameter \\#1 \\$objects \\(non\\-empty\\-array\\<Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransactionDtoInterface\\|Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransferDtoInterface\\>\\) of method Bavix\\\\Wallet\\\\Services\\\\AssistantService\\:\\:getUuids\\(\\) should be compatible with parameter \\$objects \\(non\\-empty\\-array\\<string\\>\\) of method Bavix\\\\Wallet\\\\Services\\\\AssistantServiceInterface\\:\\:getUuids\\(\\)$#"
count: 1
path: src/Services/AssistantService.php

-
message: "#^Parameter \\#2 \\$second of method Bavix\\\\Wallet\\\\Internal\\\\Service\\\\MathServiceInterface\\:\\:add\\(\\) expects float\\|int\\|non\\-empty\\-string, float\\|int\\|string given\\.$#"
count: 1
path: src/Services/AssistantService.php

-
message: "#^Parameter \\#1 \\$objects of method Bavix\\\\Wallet\\\\Services\\\\AssistantServiceInterface\\:\\:getUuids\\(\\) expects non\\-empty\\-array\\<string\\>, non\\-empty\\-array\\<Bavix\\\\Wallet\\\\Internal\\\\Dto\\\\TransactionDtoInterface\\> given\\.$#"
count: 1
Expand All @@ -340,6 +380,21 @@ parameters:
count: 2
path: src/Services/AtmService.php

-
message: "#^Parameter \\#1 \\$uuid of method Bavix\\\\Wallet\\\\Internal\\\\Service\\\\StateServiceInterface\\:\\:drop\\(\\) expects non\\-empty\\-string, string given\\.$#"
count: 1
path: src/Services/AtomicService.php

-
message: "#^Parameter \\#1 \\$uuids of method Bavix\\\\Wallet\\\\Internal\\\\Service\\\\StateServiceInterface\\:\\:multiFork\\(\\) expects array\\<non\\-empty\\-string\\>, non\\-empty\\-array\\<int, string\\> given\\.$#"
count: 1
path: src/Services/AtomicService.php

-
message: "#^Parameter \\#2 \\$value of method Bavix\\\\Wallet\\\\Internal\\\\Service\\\\StateServiceInterface\\:\\:multiFork\\(\\) expects callable\\(\\)\\: array\\<non\\-empty\\-string, non\\-empty\\-string\\>, Closure\\(\\)\\: non\\-empty\\-array\\<string, string\\> given\\.$#"
count: 1
path: src/Services/AtomicService.php

-
message: "#^Parameter \\#1 \\$inputs of method Bavix\\\\Wallet\\\\Internal\\\\Service\\\\StorageServiceInterface\\:\\:multiIncrease\\(\\) expects non\\-empty\\-array\\<non\\-empty\\-string, float\\|int\\|non\\-empty\\-string\\>, T of non\\-empty\\-array\\<string, float\\|int\\|string\\> given\\.$#"
count: 2
Expand Down Expand Up @@ -375,11 +430,6 @@ parameters:
count: 1
path: src/Services/ConsistencyService.php

-
message: "#^Parameter \\#2 \\$second of method Bavix\\\\Wallet\\\\Internal\\\\Service\\\\MathServiceInterface\\:\\:sub\\(\\) expects float\\|int\\|non\\-empty\\-string, float\\|int\\|string given\\.$#"
count: 1
path: src/Services/ConsistencyService.php

-
message: "#^Parameter \\#1 \\$first of method Bavix\\\\Wallet\\\\Internal\\\\Service\\\\MathServiceInterface\\:\\:sub\\(\\) expects float\\|int\\|non\\-empty\\-string, float\\|int\\|string given\\.$#"
count: 1
Expand Down
6 changes: 3 additions & 3 deletions src/Interfaces/Exchangeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface Exchangeable
* Exchange currency from this wallet to another wallet.
*
* @param Wallet $to The wallet to exchange the currency to.
* @param int|string $amount The amount to exchange.
* @param int|non-empty-string $amount The amount to exchange.
* @param ExtraDtoInterface|array<mixed>|null $meta The extra data for the transaction.
* @return Transfer The created transfer.
*
Expand All @@ -38,7 +38,7 @@ public function exchange(Wallet $to, int|string $amount, ExtraDtoInterface|array
* If an error occurs during the process, null is returned.
*
* @param Wallet $to The wallet to exchange the currency to.
* @param int|string $amount The amount to exchange.
* @param int|non-empty-string $amount The amount to exchange.
* @param ExtraDtoInterface|array<mixed>|null $meta The extra data for the transaction.
* @return null|Transfer The created transfer, or null if an error occurred.
*/
Expand All @@ -54,7 +54,7 @@ public function safeExchange(
* This method will throw an exception if the exchange is not possible.
*
* @param Wallet $to The wallet to exchange the currency to.
* @param int|string $amount The amount to exchange.
* @param int|non-empty-string $amount The amount to exchange.
* @param ExtraDtoInterface|array<mixed>|null $meta The extra data for the transaction.
* @return Transfer The created transfer.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/ProductInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface ProductInterface extends Wallet
* by the given customer. The amount can be an integer or a string.
*
* @param Customer $customer The customer to get the amount for.
* @return int|string The amount of the product that can be purchased.
* @return int|non-empty-string The amount of the product that can be purchased.
*/
public function getAmountProduct(Customer $customer): int|string;

Expand Down
2 changes: 2 additions & 0 deletions src/Internal/Dto/ItemDtoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function getItems(): array;

/**
* Returns the price per item in the DTO.
*
* @return int|non-empty-string|null
*/
public function getPricePerItem(): int|string|null;

Expand Down
6 changes: 6 additions & 0 deletions src/Internal/Dto/TransactionDtoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ interface TransactionDtoInterface
{
/**
* Get the UUID of the transaction.
*
* @return non-empty-string
*/
public function getUuid(): string;

/**
* Get the type of the payable.
*
* @return class-string
*/
public function getPayableType(): string;

Expand All @@ -35,6 +39,8 @@ public function getType(): string;

/**
* Get the amount of the transaction.
*
* @return float|int|non-empty-string
*/
public function getAmount(): float|int|string;

Expand Down
4 changes: 4 additions & 0 deletions src/Internal/Dto/TransferDtoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ interface TransferDtoInterface
{
/**
* Get the UUID of the transfer.
*
* @return non-empty-string
*/
public function getUuid(): string;

Expand Down Expand Up @@ -45,6 +47,8 @@ public function getDiscount(): int;

/**
* Get the fee amount of the transfer.
*
* @return non-empty-string
*/
public function getFee(): string;

Expand Down
4 changes: 4 additions & 0 deletions src/Internal/Dto/TransferLazyDtoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public function getDiscount(): int;

/**
* Get the fee amount of the transfer.
*
* @return non-empty-string
*/
public function getFee(): string;

Expand All @@ -45,6 +47,8 @@ public function getStatus(): string;

/**
* Get the UUID of the transfer.
*
* @return non-empty-string|null
*/
public function getUuid(): ?string;

Expand Down
4 changes: 2 additions & 2 deletions src/Internal/Events/BalanceUpdatedEventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public function getWalletId(): int;
/**
* Returns the UUID of the wallet that was updated.
*
* @return string The UUID of the wallet.
* @return non-empty-string The UUID of the wallet.
*/
public function getWalletUuid(): string;

/**
* Returns the balance of the wallet after the update.
*
* @return string The balance of the wallet.
* @return non-empty-string The balance of the wallet.
*/
public function getBalance(): string;

Expand Down
2 changes: 2 additions & 0 deletions src/Internal/Events/WalletCreatedEventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public function getWalletId(): int;

/**
* Returns the UUID of the wallet.
*
* @return non-empty-string
*/
public function getWalletUuid(): string;

Expand Down
10 changes: 5 additions & 5 deletions src/Internal/Service/StateServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ interface StateServiceInterface
* If any of the wallets have been modified since the transaction began, a `WalletStateConsistencyException`
* exception will be thrown.
*
* @param string[] $uuids The UUIDs of the wallets to be forked.
* @param callable(): array<string, string> $value A callback function that performs a series of operations on the
* @param non-empty-string[] $uuids The UUIDs of the wallets to be forked.
* @param callable(): array<non-empty-string, non-empty-string> $value A callback function that performs a series of operations on the
* wallets and returns an associative array of the new state of the wallets.
* The keys of the array should be the UUIDs of the wallets, and the values
* should be the new state of the wallets.
Expand All @@ -29,8 +29,8 @@ public function multiFork(array $uuids, callable $value): void;
/**
* Get the state of a wallet.
*
* @param string $uuid The UUID of the wallet to retrieve the state of.
* @return string|null The state of the wallet, or null if the wallet does not exist.
* @param non-empty-string $uuid The UUID of the wallet to retrieve the state of.
* @return non-empty-string|null The state of the wallet, or null if the wallet does not exist.
*/
public function get(string $uuid): ?string;

Expand All @@ -39,7 +39,7 @@ public function get(string $uuid): ?string;
*
* This method is used to remove the state of a wallet from the storage.
*
* @param string $uuid The UUID of the wallet to delete the state of.
* @param non-empty-string $uuid The UUID of the wallet to delete the state of.
*/
public function drop(string $uuid): void;
}
4 changes: 2 additions & 2 deletions src/Internal/Transform/TransactionDtoTransformerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ interface TransactionDtoTransformerInterface
/**
* @return array{
* uuid: string,
* payable_type: string,
* payable_type: class-string,
* payable_id: int|string,
* wallet_id: int,
* type: string,
* amount: float|int|string,
* amount: float|int|non-empty-string,
* confirmed: bool,
* meta: array<mixed>|null,
* created_at: DateTimeImmutable,
Expand Down
4 changes: 2 additions & 2 deletions src/Internal/Transform/TransferDtoTransformerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ interface TransferDtoTransformerInterface
{
/**
* @return array{
* uuid: string,
* uuid: non-empty-string,
* deposit_id: int,
* withdraw_id: int,
* status: string,
* from_id: int|string,
* to_id: int|string,
* discount: int,
* fee: string,
* fee: non-empty-string,
* extra: array<mixed>|null,
* created_at: DateTimeImmutable,
* updated_at: DateTimeImmutable,
Expand Down
34 changes: 31 additions & 3 deletions src/Models/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,24 @@ public function refreshBalance(): bool

public function getOriginalBalanceAttribute(): string
{
return (string) $this->getRawOriginal('balance', 0);
$balance = (string) $this->getRawOriginal('balance', 0);

// Perform assertion to check if balance is not an empty string
assert($balance != '', 'Balance should not be an empty string');

return $balance;
}

public function getAvailableBalanceAttribute(): float|int|string
{
return $this->walletTransactions()
$balance = $this->walletTransactions()
->where('confirmed', true)
->sum('amount');

// Perform assertion to check if balance is not an empty string
assert($balance != '', 'Balance should not be an empty string');

return $balance;
}

/**
Expand All @@ -158,7 +168,25 @@ public function holder(): MorphTo

public function getCreditAttribute(): string
{
return (string) ($this->meta['credit'] ?? '0');
$credit = (string) ($this->meta['credit'] ?? '0');

/**
* Assert that the credit attribute is not an empty string.
*
* This is to ensure that the credit attribute always has a value.
* If the credit attribute is empty, it can cause issues with the math service.
*
* @throws \AssertionError If the credit attribute is an empty string.
*/
// Assert that credit is not an empty string
// This is to ensure that the credit attribute always has a value
// If the credit attribute is empty, it can cause issues with the math service
assert(
$credit != '',
'Credit should not be an empty string. It can cause issues with the math service.'
);

return $credit;
}

public function getCurrencyAttribute(): string
Expand Down

0 comments on commit 61a1883

Please sign in to comment.