Formatting for Alternative Control Structures

When using Reformat Code... on PHP files containing code written using any of the alternative control structure syntax:

while ($foo->content_of_sometype) : $bar;
    $results[] = $baz;
endwhile;


The indenting for the statement inside the control structure is too far to the right. Specifically it is right-aligned with the colon above it like so:

while ($foo->content_of_sometype) : $bar;
                                    $results[] = $baz;
endwhile;


I do not see where to change this in the Code Style preferences/settings. Can anyone point me in the correct direction?

7 comments
Comment actions Permalink

Stuart, why can't you put $bar to the next line? It would solve the problem.

0
Comment actions Permalink

Hello Rustam, I can but this is code style (used in Wordpress) is littered throughout the files of both the core Wordpress code and most templates. I would need to check each file I work on for an instance of this type of formatting (a quick and sloppy search shows 63 instances of this) before running "Reformat Code..." and that is a bit unwieldy.

I only even noticed it after something I had checked in was brought to my attention by my boss because the formatting was so off. I ran "Reformat Code..." on a file and the section that was a problem was in a part of the file I was not working in so I did not even realize it had happened.

0
Comment actions Permalink

The formatter can be fixed to put any statement after ':' to another line automatically. Maybe only in case if while/endwhile are on different lines (and similarly for if/endif etc.). Does it make sense?

0
Comment actions Permalink

Where would I edit this? I looked in the Preferences but did not see anything that seemed to me to be the place I could make such an edit.

0
Comment actions Permalink

Actually I meant a future PhpStorm/WebStorm version and this would be simply a default formatter behaviour. So this has to be implemented.

0
Comment actions Permalink

Fantastic! Thanks Rustam. In the future and for simple changes, where would such changes be made? Is there a file that I can edit to control such things?

0
Comment actions Permalink

Many things are just hard-coded for performance reasons. If there are any visible settings at configuration file level, they normally can be found in UI too. No tweaks are possible unfortunately.

0

Please sign in to leave a comment.