1

Unable to install magento-ecg/coding-standard to PHP_CodeSniffer: Tried below command after cloning PHP_CodeSniffer from github:

phpcs --config-set installed_paths ./vendor/magento-ecg/coding-standard

But phpcs -i is showing only following standards.

The installed coding standards are PSR1, MySource, Zend, Squiz, PHPCS, PEAR and PSR2

1
  • If you have a possibility try to put it in default path and see if it works: /usr/share/php/PHP/CodeSniffer/Standards/ Another thing you can try is using full path to standards directory: phpcs --config-set installed_paths /home/your_user/vendor/magento-ecg/coding-standard
    – versedi
    Commented Mar 1, 2016 at 15:20

3 Answers 3

9

facing the same problem solved it by

git clone https://github.com/magento-ecg/coding-standard

then added the complete path where you clone it

phpcs --config-set installed_paths /home/your_user/vendor/magento-ecg/coding-standard

End reuslt phpcs -i

The installed coding standards are PSR1, PSR2, PEAR, MySource, PHPCS, Zend, Squiz, Ecg and EcgM2

2
  • I have taken clone in my magento 2 folder. for below command what will be the installed_paths? Also what will be /home/your_user/vendor/magento-ecg/coding-standard? phpcs --config-set installed_paths /home/your_user/vendor/magento-ecg/coding-standard
    – jack
    Commented May 18, 2018 at 5:49
  • @jack which folder your standard is located that will be installed path Commented May 18, 2018 at 18:12
0

i followed below steps in windows local system first installed xammp

  1. cd C:\xampp\php
  2. pear install PHP_CodeSniffer pear install --alldeps PHP_CodeSniffer

(if there is any issue run cmd as Administrator)

enter image description here

phpcs -i

  1. then to follow Magento coding install magento-ecg/coding-standard from composer

  2. after install it will be in C:\xampp\htdocs\magento217\vendor\magento-ecg\

  3. now run (C:\xampp\php>)

    phpcs --config-set installed_paths C:\xampp\htdocs\magento217\vendor\magento-ecg\coding-standard

now it will have all plugins need for M2

phpcs -i

The installed coding standards are PSR1, PSR2, PEAR, MySource, PHPCS, Zend, Squiz, Ecg and EcgM2

To test Module run below code

C:\xampp\php>phpcs C:\xampp\htdocs\magento217\app\code\NAMESPACE\MODULE_NAME
0

Install Magento coding standard using following approach

  1. composer require --dev magento/magento-coding-standard

when installed this way the Magento standard for phpcs cannot be added automatically. You can achieve this by adding the following to your project's composer.json

2.

 "scripts": {
    "post-install-cmd": [
      "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
    ],
    "post-update-cmd": [
      "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
    ]
}

For more information check https://github.com/magento/magento-coding-standard

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.