Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for returning NULL-s from service methods #4

Open
1 task
maciej-sz opened this issue May 3, 2023 · 0 comments
Open
1 task

Add support for returning NULL-s from service methods #4

maciej-sz opened this issue May 3, 2023 · 0 comments
Assignees
Labels

Comments

@maciej-sz
Copy link
Owner

maciej-sz commented May 3, 2023

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

  • Decide whether or not to implement this in old API (causes BC-break), or add new API

Possible aproaches for the new API solution

  1. Introduce methods in existing services (for example tryFromDay('2023-01-01')
  2. Introduce new api classes corresponding to existing ones (something like CurrencyAverageRatesService -> CurrencyAverageRatesNullableService)
  3. Introduce some kind of switch (config variable) in existing services to change the behavior of existing methods. No BC-break, but breaks SOLID.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant