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: https://gist.github.com/3303986
<?php // 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'], $_SESSION['three'], $_SESSION['four'], $_SESSION['five'] ) && $_SESSION['one'] && $_SESSION['two'] >= 2 && $_SESSION['four'] !== '0' ) { // something }
Please sign in to leave a comment.
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
unchecked
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
https://gist.github.com/3312086
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.
Bug report:
http://youtrack.jetbrains.com/issue/WI-12562