Skip to main content

Using php-cs-fixer to format files in PhpStorm

The PhpStorm docs have a detailed guide to setting up php-cs-fixer, but the steps required to work with Sirius are summarised below.

Install php-cs-fixer locally

You need to have php-cs-fixer installed on your machine so that PhpStorm can call it to inspect your files. You can either install php-cs-fixer by installing the API PHP dependencies (cd back-end, composer install) or by installing it globally (composer global require --dev friendsofphp/php-cs-fixer).

Configure PhpStorm settings

To tell PhpStorm which rules to apply when running php-cs-fixer, open Settings | PHP | Quality Tools | PHP CS Fixer and change the “Configuration” field to .php-cs-fixer.dist.php.

To tell PhpStorm to use php-cs-fixer as the default formatter, open Settings | PHP | Quality Tools and select “PHP CS Fixer” from the list of External Formatters.

To automatically run php-cs-fixer when you save a file, open Settings | Tools | Actions on Save and enable the “Reformat code” option. Note that this may enable formatters on other files that you do not want. You can fix this by excluding certain files from reformatting.

This page was last reviewed on 8 November 2024. It needs to be reviewed again on 8 November 2025 by the page owner #opg-sirius-develop .
This page was set to be reviewed before 8 November 2025 by the page owner #opg-sirius-develop. This might mean the content is out of date.