Skip to main content

phpcs issue in Visual Studio Code, I'm receiving this warning in VS Code:

phpcs: Unable to locate phpcs. Please add phpcs to your global path or use composer decency manager to install it in your project locally.

 

How to fix

You can install phpcs by using composer global command:

composer global require squizlabs/php_codesniffer

Then in VS Code, go to 

Click Code -> Preferences -> Settings

Select User Settings and locate 'PHP CodeSniffer', or in the Search settings enter 'codesniffer'

Scroll down to 'Executatble Path' and add the following

/Users/{yourname}/.composer/vendor/bin/phpcs

Remember to replace {yourname} with machine user name

 

Different issue, similar problem

Now the issue is

phpcs: Unable to locate phpcs. Command failed: /Users/{your name}/.composer/vendor/bin

 

How to fix

Restart VS Code

Related articles

Andrew Fletcher06 Oct 2024
How to search for "text" in VS Code while excluding comments
When working with code in Visual Studio Code, you may need to search for specific instances of a function or method, such as self.logger.log. However, it can be frustrating to sift through lines that are commented out, like # self.logger.log. Fortunately, VS Code provides a powerful search feature...
Andrew Fletcher21 Sep 2024
Counting term occurrences in JSON arrays using regex in VS Code
Working on a project where the JSON dataset contains over 460,000 named records, we are preparing to upsert these records into Pinecone. However, for validation and testing purposes, it's essential to cross-check how many times a specific term appears across the dataset. To ensure data integrity, we...