Home

Awesome

sublime-phpcs

This is a plugin for Sublime Text which provides checkstyle reports using the following tools (all optional):

You can also configure the plugin to fix the issues using either

Requirements

Requirements for this plugin, should you want all the options to work:

This plugin has been tested on:

It may work with other versions, but we cannot confirm that.

Installation

Use Sublime Text’s Package Control (Tools -> Command Palette -> Package Control: Install Package -> Phpcs) to install this plugin. This is the recommended installation path.

Or

Simply checkout the git repo into “~/Library/Application Support/Sublime Text/Packages/ or the equivalent folder on Windows or Linux.

cd ~/Library/Application\ Support/Sublime\ Text/Packages/
git clone git://github.com/benmatselby/sublime-phpcs.git Phpcs

In both cases, you may need to then configure the following with the actual path to the application:

They are optional for the plugin. The path needs to include the application such as /usr/local/bin/phpcs.

In order to get the path of the application (On a Mac/Linux based environment), you can use:

which phpcs
which phpmd
which php-cs-fixer
which phpcbf

Features

Once you have right clicked on a file and selected “PHP CodeSniffer” > “Sniff this file…” you will get the output as shown below (depending on the settings you have defined):

Configuration

You can also define the configuration for the following settings, be it for a project, user settings or the default settings:

Plugin

PHP_CodeSniffer

PHP CodeSniffer Fixer

PHP Code Beautifier

PHP Linter

PHP Mess Detector

Project Based Settings

Your .project file should look something like this:

{
  "folders": [{}],
  "settings": {
    "phpcs": {
      "phpcs_additional_args": {
        "--standard": "/path/to/.composer/vendor/drupal/coder/coder_sniffer/Drupal"
      }
    }
  }
}

Of course this is a example to apply Drupal code sniffer. This could be anything. Whatever you can have on this package settings it can be overwritten under the settings -> phpcs

FAQ

What do I do when I get "OSError: [Errno 8] Exec format error"?

What do I do when I get "OSError: [Error 2] No such file or directory"?

What do I do when I get "OSError: [Errno 13] Permission denied"?

$ which phpcs
/usr/local/bin/phpcs

What if I've installed the applications using Homebrew?

If you have installed php-cs-fixer, phpmd or phpcs via homebrew then please make sure that you define the "_executable_path" option to the .phar application and not the wrapper script that is placed in your bin folder, as this will cause odd behaviour.

What other Key Bindings can I setup?

The following is a list of commands that you can bind to a keyboard shortcut:

In order to achieve this you need to add the following to one of your key bindings settings file:

{ "keys": ["ctrl+super+t"], "command": "phpcs_clear_sniffer_marks" }

To decide which "Fixer" to use, you can do:

{ "keys": ["super+k", "super+f"], "command": "phpcs_fix_this_file", "args": {"tool": "CodeBeautifier"}},

or

{ "keys": ["super+k", "super+f"], "command": "phpcs_fix_this_file", "args": {"tool": "Fixer"}},

You can then change the ctrl+super+t combination to something of your choosing.