php-fig-rectified / fig-rectified-standards

The FIG PSR-2 that actually makes sense (not political but reasonable decisions).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multi line conditions in control stuctures

ionas opened this issue · comments

If you have long conditions that break lines, there should at least be a recommendation how to format these.

That follows the PSR guidelines:

if (verylongcondition
    || anotherverylongcondition
    || foo && morelongconditions
) {
    // body
}

This can probably be found in the additions file.

That's good!
If the curly braces are set on new line I'd though do it like:

if (verylongcondition
    || anotherverylongcondition
    || foo && morelongconditions)
{
    // body
}

That's inconsistent, though.
the opening brace always goes on the end of the last line.
Otherwise this would be "opening braces on a new line" again.

The () though, are treated as array like.

Personal note: I have no issues with new line braces, just the inconsistency of PSR-2 is bollox. Same line bracers take less space to read but new line braces un-clutter the source code more. If you are working with vim on a small screen ssh maybe you want things to be more condense but if you are working on 30" 4K displays newline bracers are just great.

@dereuromark yes it was meant as a recommendation for new line braces. See my other issues/comments. I'd try to adopt PSR-2 as much as possible to make the migration easy and painless - but only where it makes sense. Imho same or new line opening braces have both benefits and cons and I'd not try to push away here from PSR-2 (but as suggested, I'd simply suggest a project or package to use ONE CONSISTENT STYLE and be done with it). See: #3

I agree that as long as you use consistent, you are good.
But by allowing both here this makes the migration and inter project comp. worse again as there might be 3 versions. And using the arguments given in the reasoning file this standard recommends "same line".

Doesn't prevent you from using the consistent new line variant if you want to.