Standard for formatting long conditions

77 views
Skip to first unread message

Sergey Karavay

unread,
Jun 21, 2017, 4:11:03 AM6/21/17
to PHP Framework Interoperability Group
Hey guys!

I'd looked through all existing coding-style standards (PSR-1, PSR-2, PSR-12) and actually failed to find any suggestions about formatting of long conditionals. We have standards for long argument lists, long "implements" lists, long "use" lists, but what about long conditions?

For example:

if (($someLongVariable && $anotherLongVariable) || $moreLongVariablesHere || $this->andEvenSomeLongMethodCall()) {
  //body here
}

Can be formatted like this:

if (
       ($someLongVariable && $anotherLongVariable) 
       || 
       $moreLongVariablesHere 
       || 
       $this->andEvenSomeLongMethodCall()
) {
  //body here
}

or like this:

if (
       ($someLongVariable && $anotherLongVariable) || 
       $moreLongVariablesHere || 
       $this->andEvenSomeLongMethodCall()
) {
  //body here
}

or in some other way.

Do we have a standard for this somewhere?

Thanks.

sv...@e7o.de

unread,
Jun 21, 2017, 4:29:24 AM6/21/17
to php...@googlegroups.com
Hey,

Yes, very nice appendix out there:

https://github.com/php-fig-rectified/fig-rectified-standards/blob/master/PSR-2-R-coding-style-guide-additions.md#multi-line-declarationconditionconcatenation

Pretty much the obvious solution if you consistently continue PSR.

Regards
Sven
> --
> You received this message because you are subscribed to the Google
> Groups "PHP Framework Interoperability Group" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to php-fig+u...@googlegroups.com.
> To post to this group, send email to php...@googlegroups.com.
> To view this discussion on the web visit
>
> https://groups.google.com/d/msgid/php-fig/3f60c18b-f847-4d89-a972-a70290a165e6%40googlegroups.com
> [1].
> For more options, visit https://groups.google.com/d/optout [2].
>
>
> Links:
> ------
> [1]
>
> https://groups.google.com/d/msgid/php-fig/3f60c18b-f847-4d89-a972-a70290a165e6%40googlegroups.com?utm_medium=email&utm_source=footer
> [2] https://groups.google.com/d/optout

Nicholas Ruunu

unread,
Jun 21, 2017, 4:48:20 AM6/21/17
to PHP Framework Interoperability Group
The multi-line conditional advice is sound, but that document has a lot of bad advice and I wouldn't pass it around.

Sergey Karavay

unread,
Jun 21, 2017, 6:03:04 AM6/21/17
to PHP Framework Interoperability Group
Thanks! Pretty much what I'm talking about.

But why it's not included into general standard (BTW I do not like formatting proposed there :) )?

среда, 21 июня 2017 г., 9:29:24 UTC+1 пользователь Max Mustermann написал:

Chuck Burgess

unread,
Jun 21, 2017, 7:02:54 AM6/21/17
to php...@googlegroups.com
That repo is not us... it's not the FIG... see how they describe themselves in their Readme -- https://github.com/php-fig-rectified/fig-rectified-standards/blob/master/README.md

To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+unsubscribe@googlegroups.com.

To post to this group, send email to php...@googlegroups.com.

Sergey Karavay

unread,
Jun 21, 2017, 10:16:05 AM6/21/17
to PHP Framework Interoperability Group, Demon...@gmail.com
Oh, yes, I did not notice that. 

But at least they have such proposal for conditions, and why PHP-FIG does not? Is it missing for some reason?

среда, 21 июня 2017 г., 12:02:54 UTC+1 пользователь Chuck Burgess написал:
Reply all
Reply to author
Forward
0 new messages