Regarding my development environment, this is the first year that I’ve made drastic changes to my toolset in several years (once I find things I really like, I tend to stick with them).
Case in point, in the last few months alone:
- I’ve moved to Atom
- I’ve found a set of packages that I really like
- I use Pressmatic (rather than MAMP)
- I use WP-CLI more than I ever have before
And with these changes come some other necessary configuration changes. Specifically, I still use PHP CodeSniffer but, out of necessity, its setup and configuration have changed.
PHP CodeSniffer with Pressmatic and Atom
Assuming that you’re using PHP CodeSniffer with Pressmatic and Atom, the following steps will walk you through what you need to do to update your environment’s configuration.
1. Install Composer
Before you install PHP CodeSniffer, make sure that you have Composer installed.
Ideally, it should be available globally on your system. To do this:
- Download the installer
- Open Terminal and navigate to the directory where you downloaded the script
- Next, run
$ php installeron the command-line.
- Finally, run
$ mv composer.phar /usr/local/bin/composerand this will move Composer to a globally accessible location on your machine.
If it’s not globally available, I assume that you’re ready to go with running it from wherever you have it installed.
2. Install WPCS and PHP CodeSniffer
If you focus specifically focused on WordPress development, then you can install both PHP CodeSniffer and the WordPress rules for the WordPress Coding Standards in a single command.
Note that you should be in the directory that you wish to install the Coding Standards. The next step will install everything into the directory out of which you’re working.
From the terminal, enter the following command:
$ composer create-project wp-coding-standards/wpcs:dev-master --no-dev
This will install the WordPress Coding Standards into the directory out of which you’re working, will install PHP CodeSniffer, define the rule set for the WordPress Coding Standards, and make the PHP CodeSniffer executable globally accessible.
3. Configuring Atom
Once you have the previous steps completed, note where you’ve installed the WordPress Coding Standards package.
- Open Atom and navigate to the PHP Linter settings screen. This should be accessible via the Atom, Packages, linter-phpcs configuration page.
- In the Executable Path text input, place the directory to the phpcs executable. In my case, I defined:
- In the Code Standard Or Config File page, you can define the rules to use. Here, you can use
WordPress-VIPor whichever set of rules you prefer.
At this point, you’re all set up to start using PHP CodeSniffer with Pressmatic and Atom.
What About Debugging?
If you’ve read any of my previous posts about WordPress development, then you know I’m a big fan of using a debugger (over printing out the value of variables to the screen).
And if you’ve swapped over to Pressmatic and are wondering how to configure the environment to use Xdebug, then see my previous post, too.