[SOLVED] Unable to locate phpcs. Please add phpcs to your global path.....

[SOLVED] Unable to locate phpcs. Please add phpcs to your global path.....

How to install phpcs in Visual Studio Code on Windows 10 also remove the error phpcs: Unable to locate phpcs. Please add phpcs to your global path or use composer dependency manager to install it in your project locally.

Install Composer

  1. Step 1 - Download it.
  2. Install it, the instructions are on the download page.
  3. Make it globally accessible in your PATH.
  4. In your System Environment Variables make sure Composer is in your PATH.
  5. i.e. C:\ProgramData\ComposerSetup\bin;

PHP

Download PHP 7 and save to C:\php7

PEAR

Using Git Bash:

cd C:
cd php7/pear
#Download the go-pear using CURL
curl -OL http://pear.php.net/go-pear.phar

Now open Windows Command Prompt as an Administrator

#Run PEAR
php go-pear.phar

As it states at the end of the install instruction, install Reg edits.

PHP Codesniffer

pear install PHP_CodeSniffer

PHPCS

Close all Command Prompts and open a new one with Admin Rights

composer global require "squizlabs/php_codesniffer=*"
phpcs --version

Visual Studio Code

Restart your Visual Studio Code and you should now not get the error: phpcs: Unable to locate phpcs. Please add phpcs to your global path or use composer dependency manager to install it in your project locally. Find a PHP file and incorrectly format it and it should now alert you.

Notes

Issue: The language server needs at least PHP 7 installed. Version found: Fix: Add C:\php7 to System Environment PATH File->Preferences->Settings->Add "php.validate.executablePath": "C:\\php7\\php.exe" Issue: The openssl extension is required for SSL/TLS protection but is not available. If you can not enable the openssl extension, you can disable this error, at your own risk, by setting the 'disable-tls' option to true. Fix: Open php.ini

Change
;extension=php_openssl.dll
#TO
extension=php_openssl.dll
#AND CHANGE
;extension_dir = "ext"
#TO
extension_dir = "ext"

Categories: Posts