| Conditions | 1 |
| Paths | 1 |
| Total Lines | 22 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 40 | public function forceExchange(Wallet $to, int $amount): Transfer |
||
| 41 | { |
||
| 42 | /** |
||
| 43 | * @var Wallet $from |
||
| 44 | */ |
||
| 45 | $from = app(WalletService::class)->getWallet($this); |
||
|
|
|||
| 46 | |||
| 47 | return DB::transaction(function () use ($from, $to, $amount) { |
||
| 48 | $rate = app(CurrencyService::class)->rate($from, $to); |
||
| 49 | $withdraw = $from->withdraw($amount); |
||
| 50 | $deposit = $to->deposit($amount * $rate); |
||
| 51 | |||
| 52 | $transfers = app(CommonService::class)->multiBrings([ |
||
| 53 | (new Bring()) |
||
| 54 | ->setStatus(Transfer::STATUS_EXCHANGE) |
||
| 55 | ->setDeposit($deposit) |
||
| 56 | ->setWithdraw($withdraw) |
||
| 57 | ->setFrom($from) |
||
| 58 | ->setTo($to) |
||
| 59 | ]); |
||
| 60 | |||
| 61 | return current($transfers); |
||
| 62 | }); |
||
| 66 |