Recently I had an SSD upgrade on my Mac. The first thing I needed to do for setting up my dev environment was to install Homebrew, Laravel Valet, and PHPCS for better code practices, along with the editor. The following items were scattered, so I’m just curating them here for future reference.
If you are a Mac user, you will need to install Homebrew & Laravel Valet; linking to official docs.
PHPCS and WPCS can be installed on any OS. Steps are almost the same. The following are steps for configuring PHPCS and WPCS for Mac and Windows.
1. Installing PHPCS
1.a Official Documentation
1.b Installing via Composer
composer global require "squizlabs/php_codesniffer=*"
2. Verify PHPCS version
phpcs --version
3. Check installed coding standards
phpcs -i
4. Installing WordPress Coding Standards
composer global require "wp-coding-standards/wpcs"
5. Configure PHPCS to use WPCS
phpcs --config-set installed_paths ~/.composer/vendor/wp-coding-standards/wpcs
6. Using PHPCS with WordPress
6.1 Using WPCS on a specific file – hello.php
phpcs --standard=WordPress /path/to/hello.php
6.2 Using WPCS on a specific plugin / theme
phpcs --standard=WordPress /path/to/wp-content/themes/theme-name/
7. PHPCS for Laravel Apps
7.1 Refer to the Official Document
7.2 Install LaravelCS
composer global require pragmarx/laravelcs
8. Configuring PHPCS with Sublime – Official Doc
8.1 Must have Sublime Package Control
https://packagecontrol.io/installation
8.2 Install SublimeLinter then SublimeLinter-phpcs.
8.3 Go to Linter Settings, create User Config, and update your phpcs path in the following my Gist.
8.4 Restart Sublime before testing PHPCS code.
If you are on Windows, Point 5 becomes:
phpcs --config-set installed_paths C:/Users/abhishek/AppData/Roaming/Composer/vendor/wp-coding-standards/wpcs
Make sure you update your system username. If you find any issue setting it up, feel free to tweet me.