Ad
  • Default User Avatar

    Thanks for your feedback, I myself am still not overly happy with this construct.
    Normally, I got used to defining small "speaking" functions with guards and pattern matching in function heads :)

    As I gave up on PHP in favor of Elixir for some years now, but was "raised" by my former co-workers for like 10 years with a "don't ever use ternaries (for they can make code even more obscure)" policy, I think, the best way (regarding readability) would be, to use a small additional function for this, if one wants to avoid ternary operators.

  • Custom User Avatar

    While this solution does work, it's best to try to avoid using else and elseif is you can. Reducing conditional statemens will help with readability not only for yourself, but also your colleagues.