This is a plugin for Sublime Text which provides checkstyle reports using the following tools (all optional):
- Linter (
php -l). This provides a convenient way to perform only a syntax check on the given PHP code.
- PHP CodeSniffer 1.3+ (
- PHP Mess Detector 1.4+ (
phpmd). It detects and reports various potential problems with the code like possible bugs, suboptimal code, overcomplicated expressions and unused parameters, methods, properties.
- Scheck 0.23+ (
scheck, part of Facebook’s pfff toolchain). This will help you find stupid mistakes like typo in your code.
You can also configure the plugin to fix the issues using either
- PHP Coding Standards Fixer 0.2+ (
php-cs-fixer). It can fix most issues in your code when you want to follow the PHP coding standards as defined in the PSR-1 and PSR-2 documents and many more.
- or PHP Code Beautifier 2.2.0+ (
phpcbf). It can automatically correct coding standard violations.
This plugin has been tested on:
- Mac OS X 10.8.2
- Ubuntu 11.10
- Windows 7
- Sublime Text 2
- Sublime Text 3
Using Sublime Text’s Package Control (recommended)
Or via git checkout in Sublime Text packages
Simply checkout the git repo into
~/Library/Application Support/Sublime Text [VERSION NUMBER]/Packages/for MacOSX or the equivalent folder on Windows or Linux.
- Make sure you have
phpinstalled on your system and check that you can use it directly-
- Now you need to have the latest
composerinstalled. Use the provided link to move it globally.
- Now install the PHP CodeSniffer, PHP Mess Detector, PHP CS Fixer and PHP Code Beautifier globally. You can also follow the links to see the install insructions for each.
- Please note absolute path of all the installed packages (On a Mac/Linux based environment), you can use:
- Now install Scheck dependencies.
Now install Scheck. If you follow the instructions mentioned in their project, you can download and setup the entire
pfffset of tools. But for our case we just need the
scheckpart. So, follow these instructions to get just that.
After following the steps, you’ll find a file called
scheckin your cloned repo. Please note the absolute path of that as you’ll need it later.
- Now you just need to setup the configuration for
sublime-phpcspackage in sublime text.
PHP Code Sniffer->
Settings - User
- Add the following json configuration-
In the above configuration, replace the paths with your install paths.
Also use either
phpcbf for fixing the errors. I’d recommend using
phpcbf as that is already isntalled with
phpcs and thus you won’t have to install
php_cs_fixer at all.
I am disabling anything happening on save, but you can change the configuration anyway you want. Find the defaults here-
Package Settings ->
PHP Code Sniffer ->
Settings - Default
Now you just need to do
P and look for
sublime-phpcs - Github Pages
PHP Command Line Options - php.net
PHP CodeSniffer - Github
PHP Mess Detector - phpmd
PHP Coding Standards Fixer - Github
PHP Code Beautifier - Github
PHP installation - php.net
Introduction - Composer
Installing Git - git-scm
Scheck Wiki - Github
pfff Wiki - Github
pfff General Install Instructions - Github
pfff Linux Install Instructions - Github
pfff MacOSX Install Instructions - Github
sublime-phpcs example configurations - Github