0

I have faced issue in "vendor/bin/phpcbf" command for resolving custom extension coding standard.

I am using Magento ver.2.3.1

Running command in project root:

vendor/bin/phpcbf "app/code/Namespace/MyModule"

But while running command through below error:

PHP Fatal error: Uncaught Error: Class 'PHP_CodeSniffer\Runner' not found in /var/www/html/magento/vendor/bin/phpcbf:17 Stack trace:

0 {main} thrown in /var/www/html/magento/vendor/bin/phpcbf on line 17

Any help would be appreciated. Thanks.

5
  • can you share a screenshot to get more idea about the error?
    – Mohit Rane
    Commented Jul 9, 2019 at 13:54
  • 1
    use whole path like this vendor/bin/phpcbf /var/www/html/magento/app/code/Vendor/Module --standard=MEQP2
    – Mohit Rane
    Commented Jul 9, 2019 at 13:55
  • can you provide the coding standard github link to know which coding standard you're using?
    – Mohit Rane
    Commented Jul 9, 2019 at 13:57
  • try phpcbf command after running this command cd magento-coding-standard
    – Mohit Rane
    Commented Jul 10, 2019 at 7:21
  • you can check it by this command which phpcbf to see if it's installed or not
    – Mohit Rane
    Commented Jul 10, 2019 at 7:44

3 Answers 3

7

Inside project

Install

composer require squizlabs/php_codesniffer:^3.4

// magento ruleset
composer require magento/magento-coding-standard

// auto ruleset installer – automatically pickup 'phpcodesniffer-standard' packages
composer require dealerdirect/phpcodesniffer-composer-installer

Usage

// should see Magento2 standard listed
vendor/bin/phpcs -i
vendor/bin/phpcbf -i

vendor/bin/phpcs --standard=Magento2 app/code/Xigen/Vehicle
vendor/bin/phpcbf --standard=Magento2 app/code/Xigen/Vehicle

vendor/bin/phpcs --standard=Magento2 app/code/Xigen/Data --report-file="Data.txt"
vendor/bin/phpcbf --standard=Magento2 app/code/Xigen/Data --report-file="Data.txt"
3
  • Get error: ERROR: the "Magento2" coding standard is not installed. The installed coding standards are Zend, PSR2, PSR1, PEAR, Squiz, MySource and PSR12 Commented Dec 18, 2019 at 10:51
  • You're not picking up the magento ruleset which means either second two composer commands didn't work or phpcs you are triggering which can be determined by path is not inside project folder Commented Dec 18, 2019 at 12:28
  • This answer does not address the actual error in the question. Commented Aug 20, 2020 at 15:26
0

This error happens, if phpcs/phpcbf are copyed into the vendor/bin directory.

The reason is, the Package itself is not registering an autoloader, and the code inside the executables is

if (is_file(__DIR__.'/../autoload.php') === true) {
    include_once __DIR__.'/../autoload.php';
} else {
    include_once 'PHP/CodeSniffer/autoload.php';
}

The first is for it locally, including a custom autoload.php from inside. The second case I think is going to the include Path, which is only working if globally installed.

To solve you have multiple options.

1.

make sure its symlinked, not copied into vendor/bin/

2.

add the autoload.php file in your project composer.json like this:

    "files": [
        "vendor/squizlabs/php_codesniffer/autoload.php"
    ],

3.

execute the file directly as vendor/squizlabs/php_codesniffer/bin/phpcs

0

Have the same issue, and fixed with this command:

composer global require squizlabs/php_codesniffer:^3.4

composer global require magento/magento-coding-standard

As result, my global phpcs -i working good do not need to call it from vendor/bin/phpcs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.