2

I'm using Ubuntu 14.04 and I'd like to check compatibility of our code as we upgrade to PHP-5.4 e.g. deprecated functions and other things that will break scripts.

I installed codesniffer like so

sudo pear install PHP_CodeSniffer 

I'm trying to install the standard I found here to

/usr/share/pear/PHP/CodeSniffer/Standards/PHPCompatibility

but, phpcs doesn't seem to find it.

Has anyone else gotten this to work?

2
  • 1
    Looks like on ubuntu you need to place it here /usr/share/php/test/PHP_CodeSniffer/CodeSniffer/Standards
    – user6614
    Jan 12, 2015 at 21:56
  • 1
    Just a small typo in your location above its tests: /usr/share/php/tests/PHP_CodeSniffer/CodeSniffer/Standards
    – CoalaWeb
    Nov 17, 2016 at 18:41

4 Answers 4

4

At my local machine it's installed here:

/usr/share/php/PHP/CodeSniffer/Standards/PHPCompatibility/

(Get it from here. )

After that I can call it with:

phpcs --standard=PHPCompatibility my_project/
1
  • verifying this on my local machine, but it have note installed via apt not composer Jan 12, 2018 at 12:21
3

There is no need to copy directories, to make PHP_CodeSniffer new coding standards. Just use phpcs --config-set to set installed_paths to the extra directories containing coding standards.

phpcs --config-set installed_paths /path/to/one

If you have more directories, you can separate them with a comma.

phpcs --config-set installed_paths /path/to/one,/path/to/two

See Configuration Options.

By default, PHP_CodeSniffer will look inside its own src/Standards directory to find installed coding standards. An installed standard appears when you use the -i command line argument and can be referenced using a name instead of a path when using the --standard command line argument. You can add install paths by setting the installed_paths configuration option.

When I install PHP_CodeSniffer coding standard like drupal/coder, I use the following command. (I also use Composer to install PHP_CodeSniffer.)

composer global require drupal/coder dealerdirect/phpcodesniffer-composer-installer

dealerdirect/phpcodesniffer-composer-installer is a Composer installation plugin that makes the coding standards automatically available to PHP_CodeSniffer without setting installed_paths each time new coding standards are added.

0

By far the best way to install it is by using Composer. Just add :

"wimg/php-compatibility": "*"

to the require-dev section of your composer.json file and run :

composer update

This should automatically install the PHPCS and the standard and allow you to run PHPCS by doing :

vendor/bin/phpcs --standard=PHPCompatibility

-2

Simply run this command in your terminal:

which phpcs

You will get something like this:

/usr/bin/phpcs
1
  • 2
    phpcs is found. phpcs isn't finding something else. Sep 1, 2016 at 12:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .