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
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
Utilize composer to download the ECG index quality. Please navigate your SSH and enter this command:
$ Composer requires magento–ecg/coding-standard.
- 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
- 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.
Some errors and warnings that your Magento code may have:
- 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.
Contact us to develop an online store with Magento 2 today at a competitive price.