antonioribeiro / laravelcs

Laravel PHP_CodeSniffer
BSD 3-Clause "New" or "Revised" License
234 stars 32 forks source link

PHP Fatal error: Interface 'PHP_CodeSniffer_Sniff' not found #13

Closed jplew closed 6 years ago

jplew commented 6 years ago

Hi there:

I am getting a fatal error when attempting to use your standard while running phpcs from the command line.

Here is the command I'm using:

$  phpcs --standard=Laravel /Users/govinda/Sites/mysite/app/Models/Blog.php
PHP Fatal error:  Interface 'PHP_CodeSniffer_Sniff' not found in /Users/govinda/.composer/vendor/pragmarx/laravelcs/Standards/Laravel/Sniffs/ControlStructures/ControlSignatureSniff.php on line 12

PHP Stack trace:
PHP   1. {main}() /Users/govinda/pear/bin/phpcs:0
PHP   2. PHP_CodeSniffer\Runner->runPHPCS() /Users/govinda/pear/bin/phpcs:18
PHP   3. PHP_CodeSniffer\Runner->init() /Users/govinda/pear/share/pear/PHP/CodeSniffer/src/Runner.php:70
PHP   4. PHP_CodeSniffer\Ruleset->__construct($config = *uninitialized*) /Users/govinda/pear/share/pear/PHP/CodeSniffer/src/Runner.php:294
PHP   5. PHP_CodeSniffer\Ruleset->registerSniffs($files = *uninitialized*, $restrictions = *uninitialized*, $exclusions = *uninitialized*) /Users/govinda/pear/share/pear/PHP/CodeSniffer/src/Ruleset.php:215
PHP   6. PHP_CodeSniffer\Autoload::loadFile($path = *uninitialized*) /Users/govinda/pear/share/pear/PHP/CodeSniffer/src/Ruleset.php:1103
PHP   7. include() /Users/govinda/pear/share/pear/PHP/CodeSniffer/autoload.php:167

Fatal error: Interface 'PHP_CodeSniffer_Sniff' not found in /Users/govinda/.composer/vendor/pragmarx/laravelcs/Standards/Laravel/Sniffs/ControlStructures/ControlSignatureSniff.php on line 12

Call Stack:
    0.0328     364632   1. {main}() /Users/govinda/pear/bin/phpcs:0
    0.0669     519088   2. PHP_CodeSniffer\Runner->runPHPCS() /Users/govinda/pear/bin/phpcs:18
    0.1921     872736   3. PHP_CodeSniffer\Runner->init() /Users/govinda/pear/share/pear/PHP/CodeSniffer/src/Runner.php:70
    0.2551    1094504   4. PHP_CodeSniffer\Ruleset->__construct(???) /Users/govinda/pear/share/pear/PHP/CodeSniffer/src/Runner.php:294
    0.2847    1111192   5. PHP_CodeSniffer\Ruleset->registerSniffs(???, ???, ???) /Users/govinda/pear/share/pear/PHP/CodeSniffer/src/Ruleset.php:215
    0.2847    1111192   6. PHP_CodeSniffer\Autoload::loadFile(???) /Users/govinda/pear/share/pear/PHP/CodeSniffer/src/Ruleset.php:1103
    0.3235    1150880   7. include('/Users/govinda/.composer/vendor/pragmarx/laravelcs/Standards/Laravel/Sniffs/ControlStructures/ControlSignatureSniff.php') /Users/govinda/pear/share/pear/PHP/CodeSniffer/autoload.php:167

In contrast, phpcs seems to work fine with PSR2. For example, the following command outputs normally:

$  phpcs --standard=PSR2 /Users/govinda/Sites/mysite/app/Models/Blog.php
FILE: /Users/govinda/Sites/mysite/app/Models/Blog.php
--------------------------------------------------------------------------------------------------------------------------
FOUND 209 ERRORS AND 6 WARNINGS AFFECTING 175 LINES
--------------------------------------------------------------------------------------------------------------------------
  14 | ERROR   | [x] Opening brace of a class must be on the line after the definition
  16 | ERROR   | [x] Spaces must be used to indent lines; tabs are not allowed
...

Some of my system info:

PHP_CodeSniffer version 3.1.1 (stable) by Squiz (http://www.squiz.net)
PEAR Version: 1.10.5
PHP Version: 7.1.8
Zend Engine Version: 3.1.0
Running on: Darwin Govindas-iMac.local 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

Is this is a namespace issue?

jplew commented 6 years ago

I solved it by downgrading PHP CodeSniffer to version 2.9.1