PHP Code Sniffer not working: Interface 'PHP_CodeSniffer_Sniff' not found

Answered

In my PhpStorm Code Sniffer does not work.

The error says "Interface 'PHP_CodeSniffer_Sniff' not found in moodle/Sniffs/Commenting/InlineCommentSniff.php on line 27". (Source is here: https://github.com/moodlehq/moodle-local_codechecker/tree/master/moodle/Sniffs/Commenting)

I have macOS 10.12, PHP 7.1.5, and PHP_CodeSniffer version 3.0.0 (stable) by Squiz (http://www.squiz.net) setup with brew.

Thanks for any hint!

9 comments
Avatar
Vladimir Luchansky
Comment actions Permalink

Hello,

Does it work fine when running Code Sniffer from command line?

0
Comment actions Permalink

Good question, Vladimir.
No, it does not.
Something with running

php composer.phar update

or anything similar I forgot for CodeSniffer to work?

0
Avatar
Vladimir Luchansky
Comment actions Permalink

I would suggest to follow installation steps from https://github.com/squizlabs/PHP_CodeSniffer again, just to be sure.

0
Comment actions Permalink

I've just installed PHP_CodeSniffer and the moodle-local_codechecker, following the given instructions, and I'm having the same issue. PhpStorm outputs the following error:

phpcs: PHP Fatal error:  Interface 'PHP_CodeSniffer_Sniff' not found in /vagrant/public/local/codechecker/moodle/Sniffs/Commenting/InlineCommentSniff.php on line 27

I'm running Moodle on a LEMP vagrant box with PHP 7.0.22 and PHP_CodeSniffer version 3.1.0 (stable).

Did you find any solution to this problem?

0
Comment actions Permalink

Hi,

Do you also have issues with running it via command line?

0
Comment actions Permalink

No I couldn't get the moodle-local_codechecker plugin to work with PHP_CodeSniffer via the CLI either.

I eventually got it all working by installing the php-codesniffer package via Ubuntu. I had previously been installing it via composer and that didn't seem to work when used in conjunction with the moodle-local_codechecker plugin.

1
Comment actions Permalink

Thanks for sharing that!

0
Comment actions Permalink

Note to myself, the steps to circumvent the error and getting phpcs to work

brew uninstall --force php-code-sniffer
brew install php-code-sniffer@2.9
echo 'export PATH="/usr/local/opt/php-code-sniffer@2.9/bin:$PATH"' >> ~/.bash_profile
ln -s /usr/local/opt/php-code-sniffer@2.9/bin/phpcs /usr/local/bin/phpcs
1
Comment actions Permalink

Luca - you saved me a lot of time here. Remind me to buy you a beer at Moodle Dach 2018!

0

Please sign in to leave a comment.