When I type in phpcs –version, instead of getting the version number, I get something like this:
/Applications/drupal/php/bin/phpcs: line 2: ?php: No such file or directory
/Applications/drupal/php/bin/phpcs: line 3: /Applications: is a directory
/Applications/drupal/php/bin/phpcs: line 4: Applications: command not found
/Applications/drupal/php/bin/phpcs: line 5: Applications: command not found
/Applications/drupal/php/bin/phpcs: line 6: Applications: command not found
/Applications/drupal/php/bin/phpcs: line 7: Applications: command not found
/Applications/drupal/php/bin/phpcs: line 8: Applications: command not found
/Applications/drupal/php/bin/phpcs: line 9: Applications: command not found
/Applications/drupal/php/bin/phpcs: line 10: Applications: command not found
/Applications/drupal/php/bin/phpcs: line 11: syntax error near unexpected token `newline'
/Applications/drupal/php/bin/phpcs: line 11: ` * @author Greg Sherwood <gsherwood@squiz.net>'
It looks like its not reading PHP correctly. What did I misconfigure?
All I did was sudo pear install PHP_CodeSniffer. When I run it again, I get:
pear/PHP_CodeSniffer is already installed and is the same as the released version 1.3.5
When PEAR does an install of PHP_CodeSniffer, it changes the first line in the main phpcs script so that the
#!line points to the PHP executable on your system.So before install, the line looks like this:
#!@php_bin@and after install, it will look something like this (depending on where PHP is installed):#!/usr/bin/phpPEAR has a config setting which tells it where that PHP executable is installed. You can see this value by running
pear config-showand looking for the value ofPHP CLI/CGI binary (php_bin). You need to make sure this value is actually the location of PHP on your system or else all installs of scripts (like PHPUnit) will have a similar problem.The best way to check this value is to run
which phpand set that value for the PEAR config variable. Then reinstall PHP_CodeSniffer so the replacement is done again.So for my system, I’d do this:
If all goes well, you should see the correct
#!line in your new phpcs file:If that looks correct, you’ll be able to run the phpcs command without problems.