How to Install PHP_CodeSniffer Using Composer

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

Before starting, 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 a composer to manage PHP_CodeSniffer is a wise choice. After all, the 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. So 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 PHP_CodeSniffer.

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 PHP_CodeSniffer, and added to your path.

composer global require "squizlabs/php_codesniffer=*"

If you want to know the path of PHP_CodeSniffer 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 PHP_CodeSniffe 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.

Related Post

How to Add Yii2 Coding Standards in PHP_CodeSniffer

In this tutorial, you will learn how to add Yii2 Coding Standards in PHP_CodeSniffer.

How to Add WordPress Coding Standards in PHP_CodeSniffer

In this tutorial, you will learn how to add WordPress Coding Standards in PHP_CodeSniffer.

Leave a Reply