PHP CodeSniffer include_once error
Solution 1
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/
Solution 2
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
Solution 3
I got this error when using PHP CodeSniffer installed via Composer.
Fixed it with:
cd /path/to/app
rm -rf vendor/
composer update
Solution 4
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
Solution 5
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/
Related videos on Youtube
thatdamnqa
Software QA. I also develop things at the weekend.
Updated on September 16, 2022Comments
-
thatdamnqa over 1 year
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
-
SDC over 11 yearsis
/usr/lib/php/pear/share/pear/
in your PHP default include list? (check php.ini)
-
-
Ingmar Boddington about 10 yearsNot quite the one I needed, but got me to a solution. Thx
-
Matt Stein almost 10 yearsMy
pear
directory was in my user folder (~/pear
), so I had to add that to theinclude_path
in php.ini. -
O V about 9 yearsI love this kind of solutions :). Thanks mister, you saved my day .
-
Cameron over 7 yearsIMHO this is a better answer than the others, just set your include path properly.