Found the problem - I was using the Windows separator (semi-colon) in the include_path instead of the Unix one (colon), so it should've been:
.:/usr/lib/php/pear/share/pear/
instead of
.;/usr/lib/php/pear/share/pear/
Question
I'm trying to install PHP CodeSniffer on OS X Mountain Lion - and I appear to be getting a strange problem
When running 'phpcs' I get the following error:
PHP Warning: include_once(PHP/CodeSniffer/CLI.php): failed to open stream: No such
file or directory in /usr/lib/php/pear/bin/phpcs on line 31
PHP Warning: include_once(): Failed opening 'PHP/CodeSniffer/CLI.php' for inclusion
(include_path='.;/usr/lib/php/pear/share/pear/') in /usr/lib/php/pear/bin/phpcs on line 31
PHP Fatal error: Class 'PHP_CodeSniffer_CLI' not found in /usr/lib/php/pear/bin/phpcs
on line 34
The file /usr/lib/php/pear/share/pear/PHP/CodeSniffer/CLI.php exists, which is confusing me
Solution 6
Found the problem - I was using the Windows separator (semi-colon) in the include_path instead of the Unix one (colon), so it should've been:
.:/usr/lib/php/pear/share/pear/
instead of
.;/usr/lib/php/pear/share/pear/
OTHER TIPS
On my configuration the PHP/ path just wasn't where phpcs expected it. I solved it via creating symlink to the missing path.
go to pear directory and run:
ln -s share/pear/PHP/ PHP
I got this error when using PHP CodeSniffer installed via Composer.
Fixed it with:
cd /path/to/app
rm -rf vendor/
composer update
This is perhaps not the best solution, but it requires no change to your path or anything else. In the file phpcs you will find a section with:
if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) {
include_once dirname(__FILE__).'/../CodeSniffer/CLI.php';
else {
include_once 'PHP/CodeSniffer/CLI.php';
}
Just add a new else if with your path to the correct file CLI.php (i.e. '/usr/local/pear/share/pear/PHP/CodeSniffer/CLI.php'):
if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) {
include_once dirname(__FILE__).'/../CodeSniffer/CLI.php';
} else if (is_file('/usr/local/pear/share/pear/PHP/CodeSniffer/CLI.php')) {
include_once '/usr/local/pear/share/pear/PHP/CodeSniffer/CLI.php';
} else {
include_once 'PHP/CodeSniffer/CLI.php';
}
Last but not least document this change for later versions and updates. In the end the solution has to be that the developer of PHPCS makes a more solid construction for finding the CLI.php
If you are using MAMP include this in your path:
export PATH=/Applications/MAMP/bin/php/php5.X.XX/lib/php:$PATH
by replacing 5.X.XX with your php version. In my case this was:
export PATH=/Applications/MAMP/bin/php/php5.4.26/lib/php:$PATH
Uninstall it and reinstall it using composer
alias php=/Applications/MAMP/bin/php/php5.6.10/bin/php;
composer global require "squizlabs/php_codesniffer=*";
Source: https://tommcfarlin.com/php-codesniffer-with-composer/
In my case -- having installed PHP-OSX -- I had to fix the symlink like so:
cd /usr/local/php5/lib/php/PHP
and then:
ln -s /usr/local/share/pear/PHP/CodeSniffer
ln -s /usr/local/share/pear/PHP/CodeSniffer.php
For what it is worth, I installed PHP using homebrew (OS X). First install was 5.6.3, but upgraded over time. The default ini file, you can find the location of the file with:
php -i | grep ini
on osx - still had path references to 5.6.3. When I updated these - specifically the include path, all worked just fine; no symlinks required.
This D:\wamp\bin\php\php_VERSION\phpcs
modification worked for me on wamp
if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) {
include_once dirname(__FILE__).'/../CodeSniffer/CLI.php';
} else if (is_file(dirname(__FILE__).'/pear/PHP/CodeSniffer/CLI.php') === true) {
include_once dirname(__FILE__).'/pear/PHP/CodeSniffer/CLI.php';
} else {
include_once 'PHP/CodeSniffer/CLI.php';
}
$cli = new PHP_CodeSniffer_CLI();
$cli->runphpcs();
I had this issue trying to run phpcs as a non-privileged user, having installed it via PEAR, as root.
Fix for me was to change permissions so that the non-privileged user could access the dependencies:
chmod -R o+rx /usr/local/lib/php/
I solved it by adding the correct path to the other directory that PHP scans for INI files (it's listed in phpinfo.php). Execute these three commands from Terminal:
sudo mkdir -p /Library/Server/Web/Config/php
sudo touch /Library/Server/Web/Config/php/local.ini
echo 'include_path = ".:'`pear config-get php_dir`'"' | sudo tee -a /Library/Server/Web/Config/php/local.ini