Total Complexity | 7 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
12 | class WalletService |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * Consider the fee that the system will receive. |
||
17 | * |
||
18 | * @param Wallet $wallet |
||
19 | * @param int $amount |
||
20 | * @return int |
||
21 | */ |
||
22 | 18 | public function fee(Wallet $wallet, int $amount): int |
|
23 | { |
||
24 | 18 | if ($wallet instanceof Taxing) { |
|
25 | 1 | return (int)($amount * $wallet->getFeePercent() / 100); |
|
26 | } |
||
27 | |||
28 | 18 | return 0; |
|
29 | } |
||
30 | |||
31 | /** |
||
32 | * The amount of checks for errors |
||
33 | * |
||
34 | * @param int $amount |
||
35 | * @throws |
||
36 | */ |
||
37 | 33 | public function checkAmount(int $amount): void |
|
38 | { |
||
39 | 33 | if ($amount < 0) { |
|
40 | 3 | throw new AmountInvalid(trans('wallet::errors.price_positive')); |
|
|
|||
41 | } |
||
42 | 30 | } |
|
43 | |||
44 | /** |
||
45 | * @param Wallet $object |
||
46 | * @return WalletModel |
||
47 | */ |
||
48 | 30 | public function getWallet(Wallet $object): WalletModel |
|
49 | { |
||
50 | 30 | if ($object instanceof WalletModel) { |
|
51 | 14 | return $object; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * @var HasWallet $object |
||
56 | */ |
||
57 | 24 | return $object->wallet; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param WalletModel $wallet |
||
62 | * @return bool |
||
63 | */ |
||
64 | 2 | public function refresh(WalletModel $wallet): bool |
|
73 | } |
||
74 | |||
75 | } |
||
76 |