

composer global require -dev dealerdirect/phpcodesniffer-composer-installer The phpcs script performs the linting function for PHP, JavaScript, and CSS files using the configured coding standards while phpcbf (PHP Code Beautifier and Fixer) attempts to automatically correct identified coding standard inconsistencies, i.e., it formats the code to look pretty. Next, we will install PHP_CodeSniffer through Composer. composer global remove dealerdirect/phpcodesniffer-composer-installerĬomposer global remove wp-coding-standards/wpcsĬomposer global remove phpcompatibility/phpcompatibility-wp Step 3 – Install PHP_CodeSniffer NOTE: Even though we have not installed any dependencies yet, the following commands are provided for reference if you ever need to remove the dependencies installed as part of this guide. In this example, XAMPP is installed in the c:\xampp\ directory and PHP is located in the c:\xampp\php\ directory.Īfter installing either option, verify that the PHP directory is included in the %PATH% variable.Ĭomposer – Update With Dependencies Command Result If you do install XAMPP, it does not need to be actively running for the other steps to work properly. For the purposes of this guide, the subsequent steps only require access to PHP so either standalone PHP or XAMPP is sufficient.

The primary advantage of using XAMPP is that it creates an all-in-one local development and testing environment to install and execute WordPress and custom code.

While you can download and install PHP as a standalone product, I prefer to install XAMPP which is a free Apache distribution containing PHP, MySQL (MariaDB), and several other products. PHP is a prerequisite for installing Composer in the next step. For those who want to publish plugins or themes as part of the official directory, linting your code against the WordPress Coding Standards significantly reduces the repeated back-and-forth issue correction cycle in the overall approval process.Īlthough I am using a Windows machine to install and run the development environment, all of the referenced applications are available on most major operating systems and the listed commands are not operating system specific. This guide is focused on linting PHP code against the WordPress Coding Standards using PHP_CodeSniffer ( phpcs and phpcbf). Generically, the term lint (or linter) refers to a class of programs that perform these functions prior to or as part of compiling, however, it originates from a specific program named ‘lint’ used for evaluating C code. Code smells are simply characteristics or constructs that may present as errors during program execution. Linting is the process of using software to analyze static code for programming errors and bugs, code smells, and stylistic errors.
