Conditions | 4 |
Paths | 4 |
Total Lines | 13 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
43 | public function rateFor($currency, $date = null): ?Rate |
||
44 | { |
||
45 | if (! $currency instanceof self) { |
||
46 | $currency = self::where('code', $currency)->firstOrFail(); |
||
47 | } |
||
48 | |||
49 | $query = $this->rates()->where('target_currency_id', $currency->id); |
||
50 | |||
51 | if ($date) { |
||
52 | $query = $query->whereDay('timestamp', $date instanceof Carbon ? $date : Carbon::parse($date)); |
||
53 | } |
||
54 | |||
55 | return $query->orderByDesc('timestamp')->first(); |
||
56 | } |
||
58 |