Formatting should be a predictable project rule, not a personal editor preference.
This guide focuses on a plain PHP workflow and can be adapted to framework-based projects where the same tools apply.
Install the formatter as a development dependency
Add PHP-CS-Fixer to the project with Composer using a version constraint compatible with the project’s PHP runtime. Commit composer.json and composer.lock so developers and CI use the same tool version.
Create a project configuration
Create a .php-cs-fixer.php configuration that defines the directories to scan, file finder rules, and selected coding standards. Start with a standard such as PSR-12 where appropriate, then add only rules the team agrees to maintain. Exclude generated files, dependencies, and cache directories.
Run a dry check before applying changes
Use the formatter’s dry-run and diff options to inspect what would change. Apply formatting to a limited set of files first. Large formatting-only changes should be separated from functional changes to make code review easier.
Connect the editor
Configure the editor’s formatter integration to call the project-local binary under vendor/bin. Ensure it uses the repository configuration rather than a developer’s global rules. Avoid enabling multiple PHP formatters on save.
Enforce the same rule in CI
Add a Composer script that checks formatting and run it in continuous integration. A check-only command should fail when files are not formatted, while developers can run the fixing command locally. Review formatter upgrades as tooling changes, not as silent background updates.
Practical verification checklist
- Confirm the editor uses the intended PHP 8.4 executable.
- Open the repository root and verify Composer dependencies.
- Run PHP linting and the project’s automated tests.
- Check that editor diagnostics match command-line results.
- Keep local credentials and production data out of the workspace.
Conclusion
A committed formatter configuration creates consistent diffs across editors and developers. Keep formatting separate from code behavior and enforce the same check locally and in CI.