Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add interfaces for High performance api handles #866

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion deptrac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,13 @@ parameters:
- Model

ApiQuery:
- Api
- Model
- Contract

Api:
- Model
- ApiQuery
- Contract
- InternalException

ApiHandler:
Expand Down
7 changes: 1 addition & 6 deletions src/External/Api/TransactionQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@
namespace Bavix\Wallet\External\Api;

use Bavix\Wallet\Interfaces\Wallet;
use Bavix\Wallet\Models\Transaction;

final readonly class TransactionQuery
final readonly class TransactionQuery implements TransactionQueryInterface
{
public const TYPE_DEPOSIT = Transaction::TYPE_DEPOSIT;

public const TYPE_WITHDRAW = Transaction::TYPE_WITHDRAW;

/**
* @param self::TYPE_DEPOSIT|self::TYPE_WITHDRAW $type
* @param array<mixed>|null $meta
Expand Down
8 changes: 4 additions & 4 deletions src/External/Api/TransactionQueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ public function __construct(
public function apply(array $objects): array
{
$wallets = $this->assistantService->getWallets(
array_map(static fn (TransactionQuery $query): Wallet => $query->getWallet(), $objects),
array_map(static fn (TransactionQueryInterface $query): Wallet => $query->getWallet(), $objects),
);

$values = array_map(
fn (TransactionQuery $query) => match ($query->getType()) {
TransactionQuery::TYPE_DEPOSIT => $this->prepareService->deposit(
fn (TransactionQueryInterface $query) => match ($query->getType()) {
TransactionQueryInterface::TYPE_DEPOSIT => $this->prepareService->deposit(
$query->getWallet(),
$query->getAmount(),
$query->getMeta(),
$query->isConfirmed(),
$query->getUuid(),
),
TransactionQuery::TYPE_WITHDRAW => $this->prepareService->withdraw(
TransactionQueryInterface::TYPE_WITHDRAW => $this->prepareService->withdraw(
$query->getWallet(),
$query->getAmount(),
$query->getMeta(),
Expand Down
2 changes: 1 addition & 1 deletion src/External/Api/TransactionQueryHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface TransactionQueryHandlerInterface
* If there is a need to check the balance, then you need to wrap the method call in the AtomicServiceInterface
* and check the correctness of the balance manually.
*
* @param non-empty-array<TransactionQuery> $objects
* @param non-empty-array<TransactionQueryInterface> $objects
*
* @return non-empty-array<string, Transaction>
*
Expand Down
33 changes: 33 additions & 0 deletions src/External/Api/TransactionQueryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Bavix\Wallet\External\Api;

use Bavix\Wallet\Interfaces\Wallet;
use Bavix\Wallet\Models\Transaction;

interface TransactionQueryInterface
{
public const TYPE_DEPOSIT = Transaction::TYPE_DEPOSIT;

public const TYPE_WITHDRAW = Transaction::TYPE_WITHDRAW;

/**
* @return self::TYPE_DEPOSIT|self::TYPE_WITHDRAW
*/
public function getType(): string;

public function getWallet(): Wallet;

public function getAmount(): float|int|string;

/**
* @return array<mixed>|null
*/
public function getMeta(): ?array;

public function isConfirmed(): bool;

public function getUuid(): ?string;
}
2 changes: 1 addition & 1 deletion src/External/Api/TransferQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Bavix\Wallet\External\Contracts\ExtraDtoInterface;
use Bavix\Wallet\Interfaces\Wallet;

final readonly class TransferQuery
final readonly class TransferQuery implements TransferQueryInterface
{
/**
* @param array<mixed>|ExtraDtoInterface|null $meta
Expand Down
4 changes: 2 additions & 2 deletions src/External/Api/TransferQueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public function __construct(
public function apply(array $objects): array
{
$wallets = $this->assistantService->getWallets(
array_map(static fn (TransferQuery $query): Wallet => $query->getFrom(), $objects),
array_map(static fn (TransferQueryInterface $query): Wallet => $query->getFrom(), $objects),
);

$values = array_map(
fn (TransferQuery $query) => $this->prepareService->transferLazy(
fn (TransferQueryInterface $query) => $this->prepareService->transferLazy(
$query->getFrom(),
$query->getTo(),
Transfer::STATUS_TRANSFER,
Expand Down
2 changes: 1 addition & 1 deletion src/External/Api/TransferQueryHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface TransferQueryHandlerInterface
* If there is a need to check the balance, then you need to wrap the method call in the AtomicServiceInterface
* and check the correctness of the balance manually.
*
* @param non-empty-array<TransferQuery> $objects
* @param non-empty-array<TransferQueryInterface> $objects
*
* @return non-empty-array<string, Transfer>
*
Expand Down
22 changes: 22 additions & 0 deletions src/External/Api/TransferQueryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Bavix\Wallet\External\Api;

use Bavix\Wallet\External\Contracts\ExtraDtoInterface;
use Bavix\Wallet\Interfaces\Wallet;

interface TransferQueryInterface
{
public function getFrom(): Wallet;

public function getTo(): Wallet;

public function getAmount(): float|int|string;

/**
* @return array<mixed>|ExtraDtoInterface|null
*/
public function getMeta(): array|ExtraDtoInterface|null;
}
Loading