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

3 thoughts on “PHP Code Beautifier and Fixer (phpcbf)”

  1. Your web page has given myself a lot of very helpful guidance, and
    for which I thank you very much. This post is the best I have
    read so far on your website, and so I felt I had to take time to post a comment.
    You’ve provided myself a few tips that could aid me down the road.

Leave a 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.