In the case where a ternary operator is used in a longish expression (>80 char), it can be desirable to break it across multiple lines. Doing so produces an error about using spaces-vs-newlines.

I've posted an example at https://gist.github.com/totten/4c3fad133d21d482b19a . (I tried posting here, but the preview comes out a little wonky.)

Of the issues I'm reporting, this one feels like the most subjective/debatable:

  • One on hand, if a ternary expression is really long, then perhaps it should be broken out into an if/else. That produces 6 sloc (which look a bit sparse) instead of 2-3 sloc (which look a bit dense), and some might prefer the sparse look.
  • One the other hand, if one is constructing an array-tree (which is traditionally quite common in Drupal code), using an if/else requires a temporary variable (i.e. more indirection) which can make it harder to read.

Comments

  • klausi committed 7a8406a on 8.x-2.x
    Issue #2408923: Allow multi-line statements with operators and do not...
klausi’s picture

Status: Active » Fixed

Committed a fix, thanks for reporting!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.