Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix the following phpcs error in Visual Studio Code?

I am new to VS code. I am trying to work with PHP, but I keep getting this notification.

phpcs: Request workspace/configuration failed with message:unable to locate phpcs. please add phpcs to your global path or use composer dependency manager to install it in your project locally.

Intellisense doesn't work for PHP too. I am using a Windows system. I tried to download and install Composer, but I am still getting the problem as shown in the screenshot.

[screenshot]1

I have some extensions installed which are visible in the screenshot, but the issue persists.

like image 386
Prince Atti Avatar asked Apr 28 '18 15:04

Prince Atti


People also ask

How do I enable Phpcs?

In the Settings dialog, go to Editor > Inspections. From the inspections screen, expand the PHP | Quality tools node and enable “PHP CodeSniffer validation”. In the configuration pane that is now enabled, select “Custom” from the “Coding standard” dropdown, locate the ruleset configuration ( phpcs.

How do I download Phpcs?

Open Visual Studio Code. Press Ctrl+P on Windows or Cmd+P on Mac to open the Quick Open dialog. Type ext install phpcs to find the extension. Press Enter or click the cloud icon to install it.


1 Answers

The easiest way is to use composer to install phpcs globally and symlink the binary into your path;

Assuming you have composer installed and are using osx or linux (if not, follow instructions from here: composer) then install phpcs globally: open your terminal and type:

composer global require "squizlabs/php_codesniffer=*"

You will then need to make sure phpcs is in your path. The easiest way is to symlink into /usr/local/bin. open your terminal and type:

sudo ln -s ~/.composer/vendor/bin/phpcs /usr/local/bin/phpcs
like image 96
Jonathan Avatar answered Sep 21 '22 10:09

Jonathan