Recently I’d SSD upgrade on my mac, the first thing I need to do for Setting Dev Environment was to Install Homebrew, Laravel Valet and PHPCS for Better Code Practices and the Editor. Following items were scattered, just curating them for future reference.
PHPCS and WPCS can be installed on any OS. Steps are almost same, 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
3. Check Installed Coding Standards
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 PHP CS with WordPress
6.1 using WPCS on specific file – hello.php
phpcs --standard=WordPress /path/to/hello.php
6.2 using WPCS on specific Plugin / Theme
phpcs --standard=WordPress /path/to/wp-content/themes/theme-name/
7. PHPCS for Laravel Apps –
7.1 Refer Official Document
7.2 Install LaravelCS
composer global require pragmarx/laravelcs
8. Configuring PHPCS with Sublime – Official Doc
8.1 Must have Sublime Package Controller
8.2 Install SublimeLinter then SublimeLinter-phpcs.
8.3 Go to Linter Settings, Create User Config. Update your phpcs path in the following My GIST
8.4 Restart Sublime, Before Testing phpcs code
If you are on Windows, Point Number 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.