PHP Code Beautifier and Fixer (phpcbf)

Authored by

All of us PHP developers should be very well familiar with WordPress Coding Standards for PHP_CodeSniffer (phpcs). It automatically finds problems in WordPress code, both in terms of code style but also in terms of performance and security. It should be configured in your IDE and called in your repos’ pre-commit hooks.

Did you also know that PHP_CodeSniffer includes a tool called phpcbf (PHP Code Beautifier and Fixer) that can automatically fix a lot of the issues that PHPCS discovers?

So to do an initial pass to fix a plugin’s PHP code, you can just run:

phpcbf --standard=WordPress-Core php/*.php

This is great for automating the accommodation for WordPress’s affection for whitespace 🙂

Check out Using the PHP Code Beautifier and Fixer.

#cli #phpcs

One thought on “PHP Code Beautifier and Fixer (phpcbf)”

Leave a Reply to jaroslav.polakovic Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.