How to Install PHP_CodeSniffer Using Composer

In this tutorial, you will learn how to install PHP_CodeSniffer using Composer on Windows.

Before to start, you should know what PHP_CodeSniffer or PHPCS is. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent. PHPCS is a short form of it.

In my point of view using composer to manage PHP_CodeSniffer is a wise choice. After all composer is just a tool for dependency management in PHP i.e. it allows you to add and manage script libraries and packages as dependencies in your project, in order to reduce development time and have the ability to take advantage of third-party code.

Install Composer

If you don’t have composer installed on your computer then hop over to getcomposer.org.

The easiest way to get Composer set up on your machine by using Installer. Sp download and run Composer-Setup.exe. It will install the latest Composer version and set up your PATH so that you can call composer from any directory in your command line.

To make sure the installation completed successfully, run the following command:

composer help

Now move on to next step actually installing PHPCS.

Install PHP_CodeSniffer

To install PHP_CodeSniffer, use the following command, drop it to your command line, hit enter and let compose go out grab PHPCS and added to your path.

composer global require "squizlabs/php_codesniffer=*"

If you want to know the path of PHPCS in your PC. then use the following command in windows

where.exe phpcs

On Mac, you can use the following command

which phpcs

If you want to know your current PHPCS version, then you can use the following command

phpcs --version

If you want to know current installed coding standards, then use the following command

phpcs -i

Conclusion

You have learned how to install PHP_CodeSniffer using Composer on Windows.

Leave a Reply