@@ -111,7 +111,7 @@ public static function historic(string $currency, mixed $date = null): float
111111 *
112112 * @return array<string, float>
113113 */
114- public static function timeSeriesRates (string | array $ currency , mixed $ start = null , mixed $ end = null ): array
114+ public static function timeSeriesRates (? string $ currency = null , mixed $ start = null , mixed $ end = null ): array
115115 {
116116 if (empty ($ start )) {
117117 return [];
@@ -132,19 +132,18 @@ public static function timeSeriesRates(string|array $currency, mixed $start = nu
132132 return $ dateRange ;
133133 }
134134
135- [$ currency , $ adjustment ] = self ::getCurrencyAliasAdjustments ($ currency );
136-
135+ // handle currency alias
137136 if (! empty ($ currency )) {
138137
139- $ currencies = Arr:: wrap ($ currency );
138+ [ $ currency , $ adjustment ] = self :: getCurrencyAliasAdjustments ($ currency );
140139
141140 } else {
142141
143- $ currencies = Currency::all ()->pluck ('currency ' )->toArray ();
142+ $ currency = Currency::all ()->pluck ('currency ' )->toArray ();
144143 }
145144
146145 // get rates
147- $ rates = Frankfurter::setSymbols ($ currencies )->timeSeries ($ period ->first (), $ period ->last ());
146+ $ rates = Frankfurter::setSymbols ($ currency )->timeSeries ($ period ->first (), $ period ->last ());
148147
149148 $ rates = collect (Arr::get ($ rates , 'rates ' , []))->sortKeys ()->toArray ();
150149
@@ -177,13 +176,18 @@ public static function timeSeriesRates(string|array $currency, mixed $start = nu
177176 // persist
178177 self ::chunkInsert ($ updates );
179178
180- return collect ($ updates )
181- ->whereBetween ('date ' , [$ start , $ end ?? now ()])
182- ->where ('currency ' , $ currency )
183- ->mapWithKeys (fn ($ rate ) => [
184- $ rate ['date ' ] => $ rate ['rate ' ] * $ adjustment ,
185- ])
186- ->toArray ();
179+ if (is_string ($ currency )) {
180+
181+ return collect ($ updates )
182+ ->whereBetween ('date ' , [$ start , $ end ?? now ()])
183+ ->where ('currency ' , $ currency )
184+ ->mapWithKeys (fn ($ rate ) => [
185+ $ rate ['date ' ] => $ rate ['rate ' ] * ($ adjustment ?? 1 ),
186+ ])
187+ ->toArray ();
188+ }
189+
190+ return [];
187191 }
188192
189193 private static function getNearestPastDate (CarbonInterface $ date , array $ datesOnly , array $ rates ): ?CarbonInterface
@@ -265,7 +269,7 @@ public static function chunkInsert(array $updates): void
265269 }
266270 }
267271
268- protected static function getCurrencyAliasAdjustments ($ currency )
272+ protected static function getCurrencyAliasAdjustments (string $ currency )
269273 {
270274 $ adjustment = 1 ;
271275
0 commit comments