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