Skip to content

Commit

Permalink
Add interfaces for High performance api handles
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Jan 24, 2024
1 parent 8f57694 commit 1c2ad52
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 15 deletions.
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

Check failure on line 9 in src/External/Api/TransactionQuery.php

View workflow job for this annotation

GitHub Actions / deptrac

Bavix\Wallet\External\Api\TransactionQuery must not depend on Bavix\Wallet\External\Api\TransactionQueryInterface (ApiQuery on Api)
{
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;

Check failure on line 7 in src/External/Api/TransactionQueryInterface.php

View workflow job for this annotation

GitHub Actions / deptrac

Bavix\Wallet\External\Api\TransactionQueryInterface must not depend on Bavix\Wallet\Interfaces\Wallet (Api on Contract)
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;

Check failure on line 21 in src/External/Api/TransactionQueryInterface.php

View workflow job for this annotation

GitHub Actions / deptrac

Bavix\Wallet\External\Api\TransactionQueryInterface must not depend on Bavix\Wallet\Interfaces\Wallet (Api on Contract)

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

Check failure on line 10 in src/External/Api/TransferQuery.php

View workflow job for this annotation

GitHub Actions / deptrac

Bavix\Wallet\External\Api\TransferQuery must not depend on Bavix\Wallet\External\Api\TransferQueryInterface (ApiQuery on Api)
{
/**
* @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;

Check failure on line 7 in src/External/Api/TransferQueryInterface.php

View workflow job for this annotation

GitHub Actions / deptrac

Bavix\Wallet\External\Api\TransferQueryInterface must not depend on Bavix\Wallet\External\Contracts\ExtraDtoInterface (Api on Contract)
use Bavix\Wallet\Interfaces\Wallet;

Check failure on line 8 in src/External/Api/TransferQueryInterface.php

View workflow job for this annotation

GitHub Actions / deptrac

Bavix\Wallet\External\Api\TransferQueryInterface must not depend on Bavix\Wallet\Interfaces\Wallet (Api on Contract)

interface TransferQueryInterface
{
public function getFrom(): Wallet;

Check failure on line 12 in src/External/Api/TransferQueryInterface.php

View workflow job for this annotation

GitHub Actions / deptrac

Bavix\Wallet\External\Api\TransferQueryInterface must not depend on Bavix\Wallet\Interfaces\Wallet (Api on Contract)

public function getTo(): Wallet;

Check failure on line 14 in src/External/Api/TransferQueryInterface.php

View workflow job for this annotation

GitHub Actions / deptrac

Bavix\Wallet\External\Api\TransferQueryInterface must not depend on Bavix\Wallet\Interfaces\Wallet (Api on Contract)

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

/**

Check failure on line 18 in src/External/Api/TransferQueryInterface.php

View workflow job for this annotation

GitHub Actions / deptrac

Bavix\Wallet\External\Api\TransferQueryInterface must not depend on Bavix\Wallet\External\Contracts\ExtraDtoInterface (Api on Contract)
* @return array<mixed>|ExtraDtoInterface|null
*/
public function getMeta(): array|ExtraDtoInterface|null;

Check failure on line 21 in src/External/Api/TransferQueryInterface.php

View workflow job for this annotation

GitHub Actions / deptrac

Bavix\Wallet\External\Api\TransferQueryInterface must not depend on Bavix\Wallet\External\Contracts\ExtraDtoInterface (Api on Contract)
}

0 comments on commit 1c2ad52

Please sign in to comment.