Symfony code style
PhpStorm provides the built-in Symfony2 code style tailored for Symfony development.
Set the Symfony2 code style
In the Settings dialog (Ctrl+Alt+S) , navigate to .
Click the Set from link in the upper-right corner and select the Symfony2 option from the popup menu.
Check code against the Symfony coding standards
With PhpStorm, you can use the PHP_CodeSniffer tool, which detects coding standard issues, in combination with Symfony coding standard, which provides a set of Symfony-specific standards to PHP_CodeSniffer. This will ensure that your code is clean, consistent, and free of some common errors.
To get started, install PHP_CodeSniffer using any technique described in Install and configure PHP_CodeSniffer. Probably the easiest way is to install it with Composer.
Install PHP_CodeSniffer
Inside composer.json, add the
squizlabs/php_codesniffer
dependency record to therequire
orrequire-dev
key. To get code completion for the package name and version, press Ctrl+Space.Do one of the following:
Click the Install shortcut link on top of the editor panel.
If the Non-installed Composer packages inspection is enabled, PhpStorm will highlight the declared dependencies that are not currently installed. Press Alt+Enter and select whether you want to install a specific dependency or all dependencies at once.
Next, install Symfony coding standard, which will provide Symfony-specific standards to PHP_CodeSniffer.
Install Symfony coding standard
Inside composer.json, add the
escapestudios/symfony2-coding-standard
dependency record to therequire
orrequire-dev
key. To get code completion for the package name and version, press Ctrl+Space.Do one of the following:
Click the Install shortcut link on top of the editor panel.
If the Non-installed Composer packages inspection is enabled, PhpStorm will highlight the declared dependencies that are not currently installed. Press Alt+Enter and select whether you want to install a specific dependency or all dependencies at once.
The Symfony coding standard package will be installed, and the corresponding Symfony standard will be selected for the PHP_CodeSniffer validation inspection automatically. If necessary, you can further customize the inspection on the page of the Settings dialog (Ctrl+Alt+S) . For more information, refer to Enable PHP_CodeSniffer as a PhpStorm inspection.