PHP Code Sniffer with Symfony2 Coding Standards Integration in PhpStorm
PHP Code Sniffer is a tool designed to detect violations of a defined coding standard. It is an essential development tool that helps ensure your code remains clean and consistent. It can also help prevent some common semantic errors made by developers.
PHP Code Sniffer is supported in PhpStorm, which means you can get its notifications inside the IDE editor. Symfony2-specific coding standards are easy to add in PHP Code Sniffer, so that Symfony Coding Standards violations will be shown in the IDE editor along with standard PHP Code Sniffer notifications.
2. Download Symfony2 Coding Standards rules for PHPCode Sniffer following installation guide described in the GitHub repository. The entire package can be downloaded as an archive or checked out from the git repository.
3. Unpack the downloaded archive (if needed) and navigate to the directory containing files (the one with Sniffs folder and ruleset.xml file inside). You need to move all the directory contents to /usr/share/php/PHP/CodeSniffer/Standards/Symfony2 (the path depends on your configuration). A file named ruleset.xml should be in this directory as well as some other subdirectories.
4. Configure PHP Code Sniffer by providing the path in Project Settings | PHP | Code Sniffer. Click the Validate button to check if the Code Sniffer tool can be reached.
5. Turn on PHP Code Sniffer inspections in Project Settings | Inspections | PHP | PHP Code Sniffer validation. Select the Symfony2 coding standard in the list (use the Refresh button if needed). Click OK to enable these new settings.
6. Now your code is inspected by PHP Code Sniffer with Symfony2 Coding Standards, in addition to PhpStorm's inspections. You will see notifications marked with phpcs in the editor.
7. If we run batch inspections with Code | Inspect Code, the results of PHP Code Sniffer inspections will be listed in the section PHP | PHP Code Sniffer validation.
Check PHP Code Sniffer in PhpStorm for more information on using this tool.