Chris Wiegman Chris Wiegman

Using PHPCS with Homebrew On MacOS Monterey

Homebrew Is the Missing Package Manager for Linux

If you’ve been using Homebrew for a while on your Mac getting PHP_CodeSniffer (PHPCS) running with the WordPress Coding Standards was pretty easy. Simply install Composer and run it all and you were good to go.

With macOS Monterey Apple stopped bundling PHP automatically. In response Composer has added the latest PHP (8.1 as of this post) as a dependency. This combination breaks the WordPress Coding Standards with numerous errors.

The workaround, at least for me, wasn’t as strait forward as I would’ve liked. If you’re finding the same issue, here’s how you fix it.

Remove PHP 8.1 and Composer

brew uninstall composer
brew uninstall phpCode language: Bash (bash)

Reinstall Composer without the PHP 8.1 dependency

brew install composer --ignore-dependenciesCode language: Bash (bash)

Install PHP 8.0

brew install php@8.0Code language: Bash (bash)

That’s all it takes. Now your linting should work in your favorite editor like it always has.