Skip to content

Commit 659cfa8

Browse files
committed
update deptrac rules
1 parent e7b1633 commit 659cfa8

18 files changed

+216
-104
lines changed

.phpstorm.meta.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
use Bavix\Wallet\Internal\Repository\TransferRepositoryInterface;
1010
use Bavix\Wallet\Services\CastServiceInterface;
1111
use Bavix\Wallet\Internal\Service\JsonServiceInterface;
12-
use Bavix\Wallet\Internal\Service\PrepareServiceInterface;
12+
use Bavix\Wallet\Services\DiscountServiceInterface;
13+
use Bavix\Wallet\Services\PrepareServiceInterface;
1314
use Bavix\Wallet\Internal\Transform\TransactionDtoTransformerInterface;
1415
use Bavix\Wallet\Internal\Transform\TransferDtoTransformerInterface;
1516
use Bavix\Wallet\Models\Transaction;
@@ -33,6 +34,7 @@
3334
use Bavix\Wallet\Services\CommonServiceLegacy;
3435
use Bavix\Wallet\Services\LockServiceLegacy;
3536
use Bavix\Wallet\Services\MetaServiceLegacy;
37+
use Bavix\Wallet\Services\TaxServiceInterface;
3638
use Bavix\Wallet\Services\WalletServiceLegacy;
3739

3840
override(\app(0), map([
@@ -50,7 +52,6 @@
5052
JsonServiceInterface::class => JsonServiceInterface::class,
5153
LockServiceInterface::class => LockServiceInterface::class,
5254
MathServiceInterface::class => MathServiceInterface::class,
53-
PrepareServiceInterface::class => PrepareServiceInterface::class,
5455
StorageServiceInterface::class => StorageServiceInterface::class,
5556
TranslatorServiceInterface::class => TranslatorServiceInterface::class,
5657
UuidServiceInterface::class => UuidServiceInterface::class,
@@ -74,8 +75,11 @@
7475
BookkeeperServiceInterface::class => BookkeeperServiceInterface::class,
7576
CastServiceInterface::class => CastServiceInterface::class,
7677
ConsistencyServiceInterface::class => ConsistencyServiceInterface::class,
78+
DiscountServiceInterface::class => DiscountServiceInterface::class,
7779
ExchangeServiceInterface::class => ExchangeServiceInterface::class,
80+
PrepareServiceInterface::class => PrepareServiceInterface::class,
7881
PurchaseServiceInterface::class => PurchaseServiceInterface::class,
82+
TaxServiceInterface::class => TaxServiceInterface::class,
7983

8084
// lagacy.services
8185
CommonServiceLegacy::class => CommonServiceLegacy::class,

config/config.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Bavix\Wallet\Internal\Service\JsonService;
1212
use Bavix\Wallet\Internal\Service\LockService;
1313
use Bavix\Wallet\Internal\Service\MathService;
14-
use Bavix\Wallet\Internal\Service\PrepareService;
1514
use Bavix\Wallet\Internal\Service\StorageService;
1615
use Bavix\Wallet\Internal\Service\TranslatorService;
1716
use Bavix\Wallet\Internal\Service\UuidService;
@@ -26,8 +25,11 @@
2625
use Bavix\Wallet\Services\BookkeeperService;
2726
use Bavix\Wallet\Services\CastService;
2827
use Bavix\Wallet\Services\ConsistencyService;
28+
use Bavix\Wallet\Services\DiscountService;
2929
use Bavix\Wallet\Services\ExchangeService;
30+
use Bavix\Wallet\Services\PrepareService;
3031
use Bavix\Wallet\Services\PurchaseService;
32+
use Bavix\Wallet\Services\TaxService;
3133

3234
return [
3335
/**
@@ -58,7 +60,6 @@
5860
'json' => JsonService::class,
5961
'lock' => LockService::class,
6062
'math' => MathService::class,
61-
'prepare' => PrepareService::class,
6263
'storage' => StorageService::class,
6364
'translator' => TranslatorService::class,
6465
'uuid' => UuidService::class,
@@ -74,8 +75,11 @@
7475
'bookkeeper' => BookkeeperService::class,
7576
'cast' => CastService::class,
7677
'consistency' => ConsistencyService::class,
78+
'discount' => DiscountService::class,
7779
'exchange' => ExchangeService::class,
80+
'prepare' => PrepareService::class,
7881
'purchase' => PurchaseService::class,
82+
'tax' => TaxService::class,
7983
],
8084

8185
/**

depfile.yaml

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,45 @@ layers:
1010
- name: UI
1111
collectors:
1212
- type: className
13-
regex: ^Bavix\\.*Traits.*
13+
regex: ^Bavix\\.*\\Traits\\.*
14+
15+
# internal
16+
- name: AssemblerDto
17+
collectors:
18+
- type: className
19+
regex: ^Bavix\\.*\\Internal\\Assembler\\.*DtoAssembler$
20+
21+
- name: AssemblerDtoInterface
22+
collectors:
23+
- type: className
24+
regex: ^Bavix\\.*\\Internal\\Assembler\\.*DtoAssemblerInterface$
25+
26+
- name: RepositoryInterface
27+
collectors:
28+
- type: className
29+
regex: ^Bavix\\.*Internal\\Repository\\.*RepositoryInterface$
1430

1531
- name: Repository
1632
collectors:
1733
- type: className
1834
regex: ^Bavix\\.*Internal\\Repository\\.*Repository$
1935

36+
- name: Transform
37+
collectors:
38+
- type: className
39+
regex: ^Bavix\\.*Internal\\Transform\\.*DtoTransformer$
40+
41+
- name: TransformInterface
42+
collectors:
43+
- type: className
44+
regex: ^Bavix\\.*Internal\\Transform\\.*DtoTransformerInterface$
45+
2046
- name: Infra
2147
collectors:
2248
- type: className
2349
regex: ^Bavix\\.*Internal\\Service\\.*Service$
2450

51+
# contracts
2552
- name: Service
2653
collectors:
2754
- type: className
@@ -34,6 +61,7 @@ layers:
3461
- type: className
3562
regex: ^Bavix\\.*Services\\.*ServiceInterface$
3663

64+
# framework
3765
- name: ModelNotFoundException
3866
collectors:
3967
- type: className
@@ -56,20 +84,33 @@ layers:
5684

5785
ruleset:
5886
UI:
87+
- AssemblerDtoInterface # delete as soon as possible
5988
- ModelNotFoundException
6089
- ServiceInterface
6190
- Legacy # delete as soon as possible
6291
Infra:
6392
- ServiceInterface
6493
- Config
6594
- Cache
66-
- Legacy
6795
ServiceInterface:
6896
- EloquentModel
97+
Transform:
98+
- TransformInterface
99+
- Infra
100+
Repository:
101+
- RepositoryInterface
102+
- TransformInterface
69103
Service:
104+
- AssemblerDtoInterface
105+
- RepositoryInterface
70106
- ServiceInterface
71-
- Repository
72107
- EloquentModel
73108
Legacy:
109+
- AssemblerDtoInterface
110+
- ServiceInterface
111+
AssemblerDtoInterface:
112+
- EloquentModel
113+
AssemblerDto:
114+
- AssemblerDtoInterface
74115
- ServiceInterface
75116
- EloquentModel

src/Services/CommonServiceLegacy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Bavix\Wallet\Internal\Dto\TransactionDto;
1111
use Bavix\Wallet\Internal\Dto\TransferLazyDto;
1212
use Bavix\Wallet\Internal\Service\DatabaseServiceInterface;
13-
use Bavix\Wallet\Internal\Service\PrepareServiceInterface;
1413
use Bavix\Wallet\Models\Transaction;
1514
use Bavix\Wallet\Models\Transfer;
1615
use Bavix\Wallet\Models\Wallet as WalletModel;

src/Services/DiscountService.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Services;
6+
7+
use Bavix\Wallet\Interfaces\Customer;
8+
use Bavix\Wallet\Interfaces\Discount;
9+
use Bavix\Wallet\Interfaces\Wallet;
10+
11+
final class DiscountService implements DiscountServiceInterface
12+
{
13+
public function getDiscount(Wallet $customer, Wallet $product): int
14+
{
15+
if ($customer instanceof Customer && $product instanceof Discount) {
16+
return (int) $product->getPersonalDiscount($customer);
17+
}
18+
19+
return 0;
20+
}
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Services;
6+
7+
use Bavix\Wallet\Interfaces\Wallet;
8+
9+
interface DiscountServiceInterface
10+
{
11+
public function getDiscount(Wallet $customer, Wallet $product): int;
12+
}

src/Services/LockServiceLegacy.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Bavix\Wallet\Internal\Service\LockServiceInterface;
88
use Closure;
99
use function get_class;
10-
use Illuminate\Database\Eloquent\Model;
1110

1211
/**
1312
* @deprecated
@@ -25,10 +24,16 @@ public function __construct(LockServiceInterface $lockService)
2524
/**
2625
* @return mixed
2726
*/
28-
public function lock(Model $self, Closure $closure)
27+
public function lock(object $self, Closure $closure)
2928
{
29+
assert(method_exists($self, 'getKey'));
30+
$key = $self->getKey();
31+
if (method_exists($self, 'getUuid')) {
32+
$key = $self->getUuid();
33+
}
34+
3035
return $this->lockService->block(
31-
'legacy_'.get_class($self).$self->getKey(),
36+
'legacy_'.get_class($self).$key,
3237
$closure
3338
);
3439
}

src/Internal/Service/PrepareService.php renamed to src/Services/PrepareService.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,42 @@
22

33
declare(strict_types=1);
44

5-
namespace Bavix\Wallet\Internal\Service;
5+
namespace Bavix\Wallet\Services;
66

77
use Bavix\Wallet\Interfaces\Wallet;
88
use Bavix\Wallet\Internal\Assembler\TransactionDtoAssemblerInterface;
99
use Bavix\Wallet\Internal\Assembler\TransferLazyDtoAssemblerInterface;
1010
use Bavix\Wallet\Internal\Dto\TransactionDto;
1111
use Bavix\Wallet\Internal\Dto\TransferLazyDto;
12+
use Bavix\Wallet\Internal\Service\MathServiceInterface;
1213
use Bavix\Wallet\Models\Transaction;
13-
use Bavix\Wallet\Services\CastServiceInterface;
14-
use Bavix\Wallet\Services\ConsistencyServiceInterface;
15-
use Bavix\Wallet\Services\WalletServiceLegacy;
1614

1715
final class PrepareService implements PrepareServiceInterface
1816
{
1917
private TransferLazyDtoAssemblerInterface $transferLazyDtoAssembler;
2018
private TransactionDtoAssemblerInterface $transactionDtoAssembler;
19+
private DiscountServiceInterface $personalDiscountService;
2120
private ConsistencyServiceInterface $consistencyService;
22-
private WalletServiceLegacy $walletService;
2321
private CastServiceInterface $castService;
2422
private MathServiceInterface $mathService;
23+
private TaxServiceInterface $taxService;
2524

2625
public function __construct(
2726
TransferLazyDtoAssemblerInterface $transferLazyDtoAssembler,
2827
TransactionDtoAssemblerInterface $transactionDtoAssembler,
28+
DiscountServiceInterface $personalDiscountService,
2929
ConsistencyServiceInterface $consistencyService,
30-
WalletServiceLegacy $walletService,
3130
CastServiceInterface $castService,
32-
MathServiceInterface $mathService
31+
MathServiceInterface $mathService,
32+
TaxServiceInterface $taxService
3333
) {
3434
$this->transferLazyDtoAssembler = $transferLazyDtoAssembler;
3535
$this->transactionDtoAssembler = $transactionDtoAssembler;
36+
$this->personalDiscountService = $personalDiscountService;
3637
$this->consistencyService = $consistencyService;
37-
$this->walletService = $walletService;
3838
$this->castService = $castService;
3939
$this->mathService = $mathService;
40+
$this->taxService = $taxService;
4041
}
4142

4243
public function deposit(Wallet $wallet, string $amount, ?array $meta, bool $confirmed = true): TransactionDto
@@ -72,9 +73,9 @@ public function withdraw(Wallet $wallet, string $amount, ?array $meta, bool $con
7273
*/
7374
public function transferLazy(Wallet $from, Wallet $to, string $status, $amount, ?array $meta = null): TransferLazyDto
7475
{
75-
$discount = $this->walletService->discount($from, $to);
76+
$discount = $this->personalDiscountService->getDiscount($from, $to);
7677
$from = $this->castService->getWallet($from);
77-
$fee = $this->walletService->fee($to, $amount);
78+
$fee = $this->taxService->getFee($to, $amount);
7879

7980
$amountWithoutDiscount = $this->mathService->sub($amount, $discount);
8081
$depositAmount = $this->mathService->compare($amountWithoutDiscount, 0) === -1 ? '0' : $amountWithoutDiscount;

src/Internal/Service/PrepareServiceInterface.php renamed to src/Services/PrepareServiceInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Bavix\Wallet\Internal\Service;
5+
namespace Bavix\Wallet\Services;
66

77
use Bavix\Wallet\Interfaces\Wallet;
88
use Bavix\Wallet\Internal\Dto\TransactionDto;

src/Services/TaxService.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Services;
6+
7+
use Bavix\Wallet\Interfaces\MinimalTaxable;
8+
use Bavix\Wallet\Interfaces\Taxable;
9+
use Bavix\Wallet\Interfaces\Wallet;
10+
use Bavix\Wallet\Internal\Service\MathServiceInterface;
11+
12+
final class TaxService implements TaxServiceInterface
13+
{
14+
private MathServiceInterface $mathService;
15+
private CastServiceInterface $castService;
16+
17+
public function __construct(
18+
MathServiceInterface $mathService,
19+
CastServiceInterface $castService
20+
) {
21+
$this->mathService = $mathService;
22+
$this->castService = $castService;
23+
}
24+
25+
/**
26+
* @param float|int|string $amount
27+
*/
28+
public function getFee(Wallet $wallet, $amount): string
29+
{
30+
$fee = 0;
31+
if ($wallet instanceof Taxable) {
32+
$fee = $this->mathService->floor(
33+
$this->mathService->div(
34+
$this->mathService->mul($amount, $wallet->getFeePercent(), 0),
35+
100,
36+
$this->castService->getWallet($wallet)->decimal_places
37+
)
38+
);
39+
}
40+
41+
/**
42+
* Added minimum commission condition.
43+
*
44+
* @see https://github.com/bavix/laravel-wallet/issues/64#issuecomment-514483143
45+
*/
46+
if ($wallet instanceof MinimalTaxable) {
47+
$minimal = $wallet->getMinimalFee();
48+
if ($this->mathService->compare($fee, $minimal) === -1) {
49+
$fee = $minimal;
50+
}
51+
}
52+
53+
return (string) $fee;
54+
}
55+
}

0 commit comments

Comments
 (0)