Cleaning your code with PHPCBF

In addition to using PHPCS in the codebase, we also include PHPCBF tools that help clean code. This is a handy tool that can not only be used by developers locally before creating PRs for their code, but can also be automated as part of your CI/CD pipeline if you’d like. Composer scripts are included in WP Rig to facilitate this.

While SSH’d into your environment that is running composer and in the path of your development theme, you can run commands like:

composer run run-phpcbf

Check composer.json in the root of WP Rig for a full list of composer scripts that are included

This command will scan all of your theme files and attempt to fix all PHPCS errors that can be automatically fixed. It’s important to note that this process will not fix all PHPCS errors, so this is not a silver bullet, but it can greatly impact issues like tabs vs. spaces or differences in line break formatting like LF vs. CRLF.