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