How to check Magento 2 source code with M2 coding sniffer?

In this blog, the following steps help you to check Magento 2 source code with M2 coding sniffer,

Step 1: Exploit composer to download an ECG index quality

Step 2: Download source code for your server

Step 3: Type the command line to scan your code with the Magento 2 encoding

Get your eCommerce store build with Magento 2 platform, click here to get started!!!

How to check Magento 2 source code with M2 coding sniffer?

How to check Magento 2 source code with M2 coding sniffer

Hii! As you know that, the Magento 2 code utilizes the standard PSR-2 and all the extensions should track this quality. Today, I will show you how to check Magento 2 source code with an M2 coding sniffer.

ECG Magento Code Sniffer Coding Standard allows automatically to verify your code:

  • SQL queries;
  • SQL queries in a cycle;
  • Direct imaging of mage and enterprise classes;
  • Unwanted collection loading;
  • More code complexity;
  • Using dangerous functions;
  • Application of PHP Superglobals

Step 1:

Utilize composer to download the ECG index quality. Please navigate your SSH and enter this command:

$ Composer requires magentoecg/coding-standard.

Step 2:

  • Please download the source code for your server. You will notice that the “vendor” created after the composer completes the command.
    • Install paths to the PHP_CodeSniffer Standard directory:

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

Step 3:

  • Please enter the command line to make sure your code with the Magento 2 coding sniffer:

$ phpcs –standard=EcgM2 /path/to/code

  • PHP CodeSniffer will automatically verify Magento PHP files. To check design templates, you can run:

$ phpcs –standard=EcgM2 /path/to/code –extensions argument: –extensions=php,phtml.

 The following are some errors and warning which your code can include:

  • WARNING: Utilize of $this in template files is denounced: you can use $block instead of this $this in the template
  • WARNING: It is established that the inexperienced useless method has been detected: you ignore the code, but it is useless
  • WARNING: Functions cyclomatic difficulty exceeds 10: employ too much “if” or “for” in one function
  • ERROR: the use of function call_user_Func_array() is prohibited
  • WARNING: The Model LSD method load () identify in the loop: load model in the loop. You must join table inst

The above-given steps help you to How to check Magento 2 source code with M2 coding sniffer and to handle its custom options one of the tasks for all Magento 2

How to check Magento 2 source code with M2 coding sniffer?

Last Update: February 26, 2021  

February 27, 2018   1731   Nandini Ramachandran    Magento2, Source Code    
Total 1 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
Twitter
INSTAGRAM
LinkedIn