Format Code and code style settings problem

I'm stuck trying to figure out how to set PhpStorm's code style so the Format Code command produced sensible results.

I put the problem on a gist:


// On my mac, cmd-opt-L reformats my php files according to the code style in effect.
// The following is how PhpStorm auto-formats this statement. 
// What do I have to set in the code style so it comes out right?

if (isset(
     && $_SESSION['one']
     && $_SESSION['two'] >= 2
     && $_SESSION['four'] !== '0'
) {
     // something

It depends what you conside the correct format to be.
Maybe you should show a sample of how you want it to look.

Mine reformats to the if condition being 1 line except it doesn't move the last closing ) up when I copy your code.
Could be because of its length. *shrugs*

Anyway, Settings -> Code Style -> PHP -> Wrapping and Braces tab -> if()
Set to
Do not force
checked for else on new line

Also set is
Keep when formatting
Line breaks unchecked
Comment at first column checked
Control statement one line checked

Which resulted in my type of formatting, which is close

The only thing wrong is in my preference is the last ) being on a new line, which is simple enough to fix.


I'm looking for a format with the same line break positions as shown in the example but with indentation that conforms to the same rules used outside an if condition. I updated the gist to show something I think is reasonable.

Apart from the confusing mix of left and right braces, PSR is a perfectly good style guide. I'm satisfied with its notion of when to indent.


Please sign in to leave a comment.