| Conditions | 4 |
| Paths | 4 |
| Total Lines | 13 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 34 | public function rateFor($currency, $date = null): ?Rate |
||
| 35 | { |
||
| 36 | if (! $currency instanceof Currency) { |
||
| 37 | $currency = Currency::where('code', $currency)->firstOrFail(); |
||
| 38 | } |
||
| 39 | |||
| 40 | $query = $this->rates()->where('target_currency_id', $currency->id); |
||
| 41 | |||
| 42 | if ($date) { |
||
| 43 | $query = $query->whereDay('timestamp', $date instanceof Carbon ? $date : Carbon::parse($date)); |
||
| 44 | } |
||
| 45 | |||
| 46 | return $query->orderByDesc('timestamp')->first(); |
||
| 47 | } |
||
| 49 |