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
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With