Formatting Changes in PhpStorm 10
Recent versions of PhpStorm have bundled several interesting formatting changes. Let’s take a look at what formatting changes have been seen in PhpStorm 9 & 10.
Case Statement Formatting
An option for controlling the indentation of the `break` statement has been added. The standard indentation is for the `break` statement to appear on the same line as the code:
Using the Code Style settings under the Editor tab, then navigating to Wrapping and Braces -> ‘switch’ statement, you can uncheck the Indent ‘break’ from ‘case’ option to get the alternative formatting.
Now, the `break` statement will appear with the same indentation as the corresponding `case` statement.
Blank Lines Around Code
In PhpStorm 8, the option to set a minimum number of blank lines around fields was introduced. This led to some consternation as it was adding blank lines around properties and methods, which was causing undesired blank lines between the first/last property, class or method. Ensuring a minimum blank line of 1 in PhpStorm 8 would result in the following formatting:
In order to allow the Reformat Code tool to reformat the code exactly to the user’s needs, in PhpStorm 9 the Minimum Blank Lines Around options have been changed, and a new option called After Class Header was added.
Now, under the Minimum Blank Lines options (which can be found under Settings -> Code Style -> PHP -> Blank Lines), the Blank Lines Around option only affects properties, constants or method blank lines that are not adjacent to the start or end of a class. To set the minimum blank lines before and after class definition braces, use the After Class Header option.
Trailing Commas in Arrays
Another much sought-after improvement is the ability to tell the code formatter to add trailing commas when reformatting arrays. You can turn this behavior on or off by using the Add a comma after last element in multiline array option under the Other tab.
Auto-changing Case on Completion
Another brand new introduction in PhpStorm, the formatter will now change the case of `true`, `false` or `null` to the case you’ve set in the code style setting, whenever you select them using the code completion popup.
To see these options in the code completion popup, make sure you’ve got case sensitivity in code completion turned off, by selecting None in the Case sensitive completion option.
Other Minor Improvements
There have also been some more minor improvements. The formatter now adheres to blank line settings even if you’re using some of the alternative PHP syntaxes. There were also a number of bug-fixes in and around the formatting tool, and some new settings and tweaks were added, like the ability to keep comments next to the return statement in functions/methods.
– Gary and the PhpStorm Team
JetBrains
The Drive to Develop