1

I am trying to install PHPCS (PHPCompatibity) in my PHPStrom. For that I have installed PHPCS using composer with the following command:

$ composer global require "squizlabs/php_codesniffer=*". In my Ubuntu 20.04, the path to phpcs executable is ~/.config/composer/vendor/bin.

But when I move inside the above folder and try to excute phpcs from the command line, I get this:

Command 'phpcs' not found, but can be installed with:
sudo apt install php-codesniffer

The phpcbs executable also resides in the same folder and I cannot run that as well.

When I am adding the above path to PHPStorm to validate PHPCS, the validation works fine.

enter image description here

In PHPStorm, I am getting this:

PHP_CodeSniffer
    phpcs: ERROR: Referenced sniff "PHPCS23Utils" does not exist
    Run "phpcs --help" for usage information
    Open PHPCodeSniffer Inspection Settings 

And when I run phpcs --help, I get Command not found error.

It is the first time I am trying to set these things up.

1 Answers1

1

I don't know why you can't execute phpcs at the command line but I had the same error in PHPStorm for Referenced sniff "PHPCS23Utils" does not exist.

My fix was to install the PHPCSUtils from https://github.com/PHPCSStandards/PHPCSUtils

If you use composer to install you may not need to configure anything but since I had to install manually, I had to update my CodeSniffer.conf file to include the installed_paths and add both PHPCS23Utils and PHPCSUtils. So that line looked like:

  'installed_paths' => 'C:\\your\\path\\to\\PHPCS23Utils,C:\\your\\path\\to\\PHPCSUtils,C:\\your\\path\\to\\PHPCompatibility',

I'm on Windows so you'll have to adjust the path appropriately for Ubuntu. Make sure you don't have any spaces between the paths or else it will only read the first one. That tripped me up for a while. After I had that installed and the configuration updated correctly I was able to run the compatibility inspection both at the command line and in PHPStorm.