New PHP formatting options in PhpStorm 3.0

Probably some of you have already noticed the changes in PHP code style settings. Putting the new UI look aside, I’d like to focus on new options and briefly explain their meaning and functionality. I hope you find them useful for making your code look more readable and closer to coding standards like PEAR or Zend.

PhpDoc Formatting (Settings|CodeStyle|PHP|PHP Doc)

There is a number of options which allow you to control the look of your PHP doc comments on reformatting:

  • Align parameter names
    Aligns the parameters prefixed with dollar ‘$’ sign.
  • Keep blank lines
    Tells if the blank lines (either put manually or inserted on previous reformatting) should be kept. Unchecking the flag will remove any blank lines which are not required by other options. Note: blank line here of course means an empty PHDoc line prefixed with a star ‘*’ character.
  • Blank lines around parameters
    Inserts blank lines around a group of parameter descriptions each starting with @param tag.
  • Blank line before the first tag
    Separates a description from the rest of PHPDoc. Note that if “Blank lines around parameters” is checked and the first tag is @param, the flag has no effect because there is already a blank line inserted by another option.
  • Align tag comments
    Aligns comments of @param tags and other tags. The two groups of tags (@param and other) are handled separately. Tags may have multiline comments in which case the whole comment will be aligned up to another tag or a blank line. Since blank lines appear meaningful for the alignment, it makes sense to keep them (make sure the “Keep blank lines” box is checked).

Code Alignments (Settings|Code Style|PHP|Other)

  • Align key-value pairs
    If checked, tells the formatter to align key=>value pairs on hash ‘=>’ sign. That’s the options you would most likely to check right now.
  • Align consecutive assignments
    If you have a group of assignments following each other without any gaps, they will be aligned on equals ‘=’ sign. By a gap I mean either a blank line, a comment or any other operator which is not an assignment (for example, echo).

Do you miss an option or have found a bug?

In both cases you are welcome to submit a feature request or a bug report at http://youtrack.jetbrains.com. And thanks in advance for any feedback!

This blog is permanently closed.

For up-to-date information please follow to corresponding WebStorm blog or PhpStorm blog.

 
This entry was posted in Cool Feature, PhpStorm and tagged , . Bookmark the permalink.

9 Responses to New PHP formatting options in PhpStorm 3.0

  1. Bryan Green says:

    I appreciate the Code Alignments the most. The underlying code for the formatting has matured and works well.

  2. Jay R. says:

    Eek. It’s all great, except that turning on the “Blank line before first tag” option *literally* randomizes my code and throws about two dozen exceptions.

  3. rustam.vishnyakov says:

    Jay,
    it would be great if you could report them. And even better: submit a bug with a code sample which is not handled correctly. This would very much help us to identify and solve these kind of problems.

  4. Alex M. says:

    Really appreciating the parameter name alignment, was about the only thing I missed moving from Eclipse!

  5. Richard Hobson says:

    Is there a nice comprehensive list of PHP Doc settings that are supported by phpStorm? I find most of the PHP Doc information to be poorly written and organized.

    I really like the idea of it but need a good reference to use while getting started.

  6. John says:

    Great, but what always ticks me off is that such features are limited to only part of a program. This should work in JavaScript as well. Why make a program work differently for different parts of it?
    What if you build in a different “save” option in the menu’s for every language (PHP, HTML, JS, etc.). It’s the same thing. Formatting should work the same in all languages.

  7. rustam.vishnyakov says:

    @Richard
    Do you mean formatting options or other, like inspections?
    @John
    We have had different requests on the subject. Some people prefer having different code styles for different languages they are working with. But anyway, you can simply copy most of the settings from one language to another unless these settings are language-specific. You can use “Copy settings from” button at the bottom of code style settings panel for that. Unfortunately this doesn’t apply to JS doc, partly because different frameworks use their own documentation style.

  8. Andreas says:

    The alignment of consecutive assignments does not work for class constants. Would be nice if this would be possible too.

Comments are closed.