Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP CodeSniffer include_once error

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

like image 294
thatdamnqa Avatar asked Jan 10 '13 11:01

thatdamnqa


5 Answers

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
like image 169
axel freudiger Avatar answered Nov 12 '22 15:11

axel freudiger


I got this error when using PHP CodeSniffer installed via Composer.

Fixed it with:

cd /path/to/app
rm -rf vendor/
composer update
like image 6
Adrian Macneil Avatar answered Nov 12 '22 15:11

Adrian Macneil


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

like image 7
Harm Avatar answered Nov 12 '22 13:11

Harm


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
like image 1
George Mastro Avatar answered Nov 12 '22 14:11

George Mastro


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/

like image 1
user2470746 Avatar answered Nov 12 '22 15:11

user2470746