Installing PHPCS on MacOS

code, coding, web

If you’re developing for WordPress then, in my opinion, use of PHPCS to help validate your code is critical.

However, anyone can develop without necessarily being a whizz with the command line (and I include myself in that bracket). So, having just gone through a PHPCS install with a freshly-baked MacBook, I thought I’d share the process. If only for me the next time I do it.

The instructions that I use, by the way, install not just the WordPress sniffs but those from WordPress VIP as well – you can happily ignore the latter ones, but they’re there if you want to use them.

The thing about installing this all, though, is that there are dependencies. And those have dependencies. So it’s a bit of a slog getting to the actual “and now you install PHPCS” part.

  1. Install Homebrew (required to install PHP)
  2. Install PHP (required to install Composer)
  3. Install Composer (required to install PHPCS)

    Now we finally get to…
  4. Install PHPCS

The “Troubleshooting” section of those instructions give you an example of correcting the path using Bash. If you’re using ZSH, then you’d edit the file ~/.zshrc and add the line…

export PATH="$PATH:$HOME/.composer/vendor/bin"

Updating PHPCS and Sniffs

To update all-the-things, simply run this…

composer g update automattic/vipwpcs

Talk to me!

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

%d bloggers like this: