PhpStorm 2024.1 Help

Symfony code style

PhpStorm provides the built-in Symfony2 code style tailored for Symfony development.

Set the Symfony2 code style

  1. In the Settings dialog (Ctrl+Alt+S) , navigate to Editor | Code Style | PHP.

  2. Click the Set from link in the upper-right corner and select the Symfony2 option from the popup menu.

    Symfony code style settings

Checking 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

  1. Inside composer.json, add the squizlabs/php_codesniffer dependency record to the require or require-dev key. To get code completion for the package name and version, press Ctrl+Space.

  2. 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

  1. Inside composer.json, add the escapestudios/symfony2-coding-standard dependency record to the require or require-dev key. To get code completion for the package name and version, press Ctrl+Space.

  2. 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 Editor | Inspections page of the Settings dialog (Ctrl+Alt+S) . For more information, refer to Enable PHP_CodeSniffer as a PhpStorm inspection.

Last modified: 04 April 2024