More PHP Formatting Options and Bundled Code Styles for PSR-1/PSR-2 and Symfony2

You asked for it – and we responded. PhpStorm 5.0 includes several more PHP formatting options and fixes specifically targeted at PSR-1/PSR-2 and Symfony2 coding style support.

True/False/Null Constants (Settings | Code Style | PHP | Other)

The formatter is able to convert them both to upper and lower case depending on the chosen coding style. First you check the “Convert…” box and then select the type of conversion you want with radio buttons.

Blank Line Before Return Statement (Settings | Code Style | PHP | Other)

This rule is specific for Symfony2 coding style. It inserts a blank line before every return statement unless the return statement resides in a simple block:

Keep ‘)’ and ‘{‘ on one line (Settings | Code Style | PHP | Wrapping and Braces | Function declaration parameters)

This option is needed to implement the following rule which can be found, for example, in Zend and PSR-1 coding styles: “When the argument list is split across multiple lines, the closing parenthesis and opening brace MUST be placed together on their own line with one space between them” (an extract from PSR-1). Here is a short sample:

class ClassName
{
    public function myFunction(
        $arg1,
        $arg2,
        $arg3
    ) {
        // method body
    }
}

Bundled Code Style Settings for PSR-1/PSR-2 and Symfony2

Instead of manually checking every formatting option, you may just apply a predefined code style for PSR-1/PSR-2 or Symfony2 similar to previously introduced PEAR, Zend and Drupal:

If you find any kind of problems with the new options or PSR-1/PSR-2 and Symfony2 coding style support, please submit a bug report in YouTrack. We’ll do our best to fix these problems.

Develop with pleasure!
– JetBrains Web IDE Team

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.

18 Responses to More PHP Formatting Options and Bundled Code Styles for PSR-1/PSR-2 and Symfony2

  1. Rafi B. says:

    Is it possible to create new custom “bundled code styles” ourselves ?

    • rustam.vishnyakov says:

      @Rafi
      There is an API for predefined code styles. So it is possible to make a plug-in which would provide a bundled style.

  2. markux says:

    Thanks! PS: what is your color scheme into screenshot?

  3. Ben VanEvery says:

    Yes! Yes! Yes!! Thank you!

  4. Onno Lissenberg says:

    How do I get this for IntelliJ IDEA 11?

    • rustam.vishnyakov says:

      Onno,
      it should be available in plug-in repository. I think PHP plug-in build 121.390 is compatible with Intellij IDEA 11 (build 118.430 or later).

      • Onno Lissenberg says:

        I got the IDEA 11 build 117.963 (Mac version) and no updates available, where can I get the latest version?

        • rustam.vishnyakov says:

          Sorry, I think I misguided you. It looks like the build 118 is actually an early EAP of Intellij IDEA 12. So it means that the new PHP plug-in is available only for version 12 which is about to be released.

  5. Onno Lissenberg says:

    I bought version 11 in September, is version 12 going to cost me anything? And using the version of the plugin that you mentioned freezes version 11 on start up, luckily I could roll-back the changes without too much trouble, it was my bad, I skipped the IDEA version part ;)

    • rustam.vishnyakov says:

      As far as I know our licensing agreement gives you a possibility for free upgrades. So I think you will be able to upgrade from version 11 to version 12 at no cost. You can also post any kind of questions regarding licensing terms at http://www.jetbrains.com/company/contacts/index.jsp#contactSales.

    • rustam.vishnyakov says:

      Onno,
      unfortunately my information regarding a possibility of a free upgrade from version 11 was wrong. I’ve just got a reply from our sales: “Only personal v11 licenses, purchased on or November 7 qualify for a free
      upgrade.” Sorry for that. In any case regarding upgrade/purchase possibilities please contact our sales department.

      • Onno Lissenberg says:

        Yes, that was disappointing. Still purchased it though and it works nicely. The UI could maybe improve a little by naming the sub-styles (for each language option, e.g. name the applied PHP style as PSR-1/PSR-2), just a thought.

        Awesome product, thanks.

  6. Peter says:

    Is there a difference between PSR1/PSR2 and Symfony2 coding styles? According to the Symfony website: “Symfony follows the standards defined in the PSR-0, PSR-1 and PSR-2 documents.”

    Thanks!

    • rustam.vishnyakov says:

      Yes, there is. For example, “Add a blank line before return statements, unless the return is alone inside a statement-group (like an if statement)” is not required by PSR1/PSR2.

Comments are closed.