Sublime-phpcs

Antonio Silva - Oct 9 '23 - - Dev Community

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

  • PHP_CodeSniffer (phpcs)
  • Linter (php -l)
  • PHP Mess Detector (phpmd)
  • Scheck (scheck, part of Facebook’s pfff toolchain)

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

  • PHP Coding Standards Fixer (php-cs-fixer)
  • PHP Code Beautifier (phpcbf) application

Requirements

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

  • PHP_CodeSniffer 3.5+
  • PHPMD 2.8+
  • PHP CS Fixer version 2.6+

Installation

Use Sublime Text’s Package Control (Preferences -> Package Control -> Install Package -> Phpcs) to install this plugin.

phpcs

Configuration

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

  • phpcs_php_path
  • phpcs_executable_path
  • phpmd_executable_path
  • php_cs_fixer_executable_path

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
Enter fullscreen mode Exit fullscreen mode

Open the PHP Code Sniffer User Settings(Preferences -> Package Settings -> PHP Code Sniffer -> Settings - User):

{

    "phpcs_executable_path": "/usr/bin/phpcs",

    "phpcs_additional_args": {
        "--standard": "PSR1,PSR2,PSR12",
        "-n": ""
    },

    "phpcs_execute_on_save": true,

    "phpcbf_executable_path": "/usr/bin/phpcbf",

    "phpcbf_on_save": true,

}
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .