Skip to content

Commit 7e9e012

Browse files
committed
Added a minimal description of methods and recommendations for development using the package to the code. Slightly stricter began to work internal methods. Added MaximalTaxable contract. Speed up events.
1 parent 6386e76 commit 7e9e012

18 files changed

+159
-32
lines changed

src/Interfaces/MaximalTaxable.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Interfaces;
6+
7+
interface MaximalTaxable extends Taxable
8+
{
9+
/**
10+
* @return float|int
11+
*/
12+
public function getMaximalFee();
13+
}

src/Interfaces/Product.php

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

77
interface Product extends Wallet
88
{
9+
/**
10+
* The method is only needed for simple projects. For more complex projects, deprecate this method and redefine the
11+
* "BasketServiceInterface" interface. Typically, in projects, this method always returns false, and the presence
12+
* interface goes to the microservice and receives data on products.
13+
*/
914
public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool;
1015

1116
/**

src/Internal/Service/DatabaseService.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ public function __construct(
3232
* @throws RecordsNotFoundException
3333
* @throws TransactionFailedException
3434
* @throws ExceptionInterface
35-
*
36-
* @return mixed
3735
*/
38-
public function transaction(callable $callback)
36+
public function transaction(callable $callback): mixed
3937
{
4038
$level = $this->connection->transactionLevel();
4139
if ($level > 0 && !$this->init) {

src/Internal/Service/DatabaseServiceInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ interface DatabaseServiceInterface
1616
* @throws TransactionStartException
1717
* @throws TransactionFailedException
1818
* @throws ExceptionInterface
19-
*
20-
* @return mixed
2119
*/
22-
public function transaction(callable $callback);
20+
public function transaction(callable $callback): mixed;
2321
}

src/Internal/Service/DispatcherService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
final class DispatcherService implements DispatcherServiceInterface
1111
{
1212
/**
13-
* @var string[]
13+
* @var array<string, bool>
1414
*/
1515
private array $events = [];
1616

@@ -21,20 +21,20 @@ public function __construct(
2121

2222
public function dispatch(EventInterface $event): void
2323
{
24-
$this->events[] = $event::class;
24+
$this->events[$event::class] = true;
2525
$this->dispatcher->push($event::class, [$event]);
2626
}
2727

2828
public function flush(): void
2929
{
30-
foreach ($this->events as $event) {
30+
foreach ($this->events as $event => $value) {
3131
$this->dispatcher->flush($event);
3232
}
3333
}
3434

3535
public function forgot(): void
3636
{
37-
foreach ($this->events as $event) {
37+
foreach ($this->events as $event => $value) {
3838
$this->dispatcher->forget($event);
3939
}
4040
}

src/Internal/Service/LockService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(CacheManager $cacheManager, ConfigRepository $config
2626
/**
2727
* @throws LockProviderNotFoundException
2828
*/
29-
public function block(string $key, callable $callback)
29+
public function block(string $key, callable $callback): mixed
3030
{
3131
return $this->getLockProvider()
3232
->lock($key)

src/Internal/Service/LockServiceInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ interface LockServiceInterface
1010
{
1111
/**
1212
* @throws LockProviderNotFoundException
13-
*
14-
* @return mixed
1513
*/
16-
public function block(string $key, callable $callback);
14+
public function block(string $key, callable $callback): mixed;
1715
}

src/Services/AssistantService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ public function __construct(
1616
}
1717

1818
/**
19-
* @param non-empty-array<TransactionDtoInterface|TransferDtoInterface> $objects
19+
* @param non-empty-array<array-key, TransactionDtoInterface|TransferDtoInterface> $objects
2020
*
21-
* @return non-empty-array<int|string, string>
21+
* @return non-empty-array<array-key, string>
2222
*/
2323
public function getUuids(array $objects): array
2424
{
2525
return array_map(static fn ($object): string => $object->getUuid(), $objects);
2626
}
2727

2828
/**
29-
* @param non-empty-array<TransactionDtoInterface> $transactions
29+
* @param non-empty-array<array-key, TransactionDtoInterface> $transactions
3030
*
3131
* @return array<int, string>
3232
*/

src/Services/AssistantServiceInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
interface AssistantServiceInterface
1111
{
1212
/**
13-
* @param non-empty-array<TransactionDtoInterface|TransferDtoInterface> $objects
13+
* @param non-empty-array<array-key, TransactionDtoInterface|TransferDtoInterface> $objects
1414
*
15-
* @return non-empty-array<int|string, string>
15+
* @return non-empty-array<array-key, string>
1616
*/
1717
public function getUuids(array $objects): array;
1818

src/Services/AtmService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Bavix\Wallet\Models\Transaction;
1414
use Bavix\Wallet\Models\Transfer;
1515

16-
/** @psalm-internal */
16+
/** @internal */
1717
final class AtmService implements AtmServiceInterface
1818
{
1919
public function __construct(
@@ -26,7 +26,7 @@ public function __construct(
2626
}
2727

2828
/**
29-
* @param non-empty-array<int|string, TransactionDtoInterface> $objects
29+
* @param non-empty-array<array-key, TransactionDtoInterface> $objects
3030
*
3131
* @return non-empty-array<string, Transaction>
3232
*/
@@ -52,7 +52,7 @@ public function makeTransactions(array $objects): array
5252
}
5353

5454
/**
55-
* @param non-empty-array<int|string, TransferDtoInterface> $objects
55+
* @param non-empty-array<array-key, TransferDtoInterface> $objects
5656
*
5757
* @return non-empty-array<string, Transfer>
5858
*/

0 commit comments

Comments
 (0)