Service methods that return null would allow using PHP 8 nullsafe operator, without the need to providing correct dates.
Example (current behavior)
$currencyAverages = CurrencyAverageRatesService::create();
// throws exeption, because there is no trading data available for this day:
$currencyAverages->formDay('2023-01-01');
Example (new behavior)
$currencyAverages = CurrencyAverageRatesService::create();
// returns null instead of throwing exception, so can be safely chained:
$currencyAverages->formDay('2023-01-01')?->fromTable('A')->getRate('USD');
Todo
Possible aproaches for the new API solution
- Introduce methods in existing services (for example
tryFromDay('2023-01-01')
- Introduce new api classes corresponding to existing ones (something like
CurrencyAverageRatesService -> CurrencyAverageRatesNullableService)
- Introduce some kind of switch (config variable) in existing services to change the behavior of existing methods. No BC-break, but breaks SOLID.
Service methods that return
nullwould allow using PHP 8 nullsafe operator, without the need to providing correct dates.Example (current behavior)
Example (new behavior)
Todo
Possible aproaches for the new API solution
tryFromDay('2023-01-01')CurrencyAverageRatesService->CurrencyAverageRatesNullableService)