Chris Wiegman

Using PHPCS with Homebrew On MacOS Monterey

/images/2020/08/homebrew-is-the-missing-package-manager-for-linux.png

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 php

Reinstall Composer without the PHP 8.1 dependency

brew install composer --ignore-dependencies

Install PHP 8.0

brew install php@8.0

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