In this post, we are learning the guide for the Magento 2 code optimization. We will discuss the below topics.
- Code Optimization
- Review the extension at the installation time
- Debug.log
- Exception.log
- system.log
1. Php bin/magento setup:config:set --enable-syslog-logging=true2. php bin/magento cache:flush
Php bin/magento setup:config:set --enable-syslog-logging=falsePhp bin/magento c:f
set of coding standards:
We need to follow the coding standard when we write the code. It’s only possible good coding practices. These standards define coding practices that determine the style of the code. Basically, Magento uses the Zend Framework. Magento 2 coding standards are based on the following.
Zend Coding Standard.
- PSR2
- PSR4
For help on our project, We strongly recommend use the PHP_CodeSniffer tool
It will help your projects coding quality and provide the no of error that you need to fix it.
Develop code to be replaceable:
We need to develop the standard code and as important as making it reusable. Writing replaceable code in your code file makes this practice easier and more efficient.
Avoid creating helper classes:
We need to avoid creating helper classes on the Magento 2 module. It will be best to create only 1 OR 2 helper classes.
Helper classes function as a static function, that is why we can be used anywhere on our module class.So, A helper class that functions as a catch-all for random methods violates the single responsibility. You need to mode the function in your appropriate classes. We can use appropriate model classes.
Avoid the around plugins:
If not required around method plugins in our module, We need to avoid it because it will affect our website performance.
A use case for around method plugins is when you need to terminate the execution of all original methods.
Write and utilize reusable code:
Always, Avoid using duplicate code which can be hard to maintain. reuse code as much as possible to prevent code duplication. Write code that is helpful to your feature development.
Code testing:
Code testing is more important for your module. You need to follow Magento 2 code testing guide.
Review the Installed Extension:
We need to always review the extension at the installation time
- Do not use Too much logic in PHTML templates in Extension.
- Coding standard stuff: Purchased modules should follow the official Magento coding standard.
- Use the ObjectManager in the correct way: When the ObjectManager is used in the wrong places, it always creates many issues.
- Too many dependencies: always use DI in the correct way. Too many dependencies were injected if it's not used the correct way.
- Always use before() and after() instead of around() plugins.
- always use LESS for design.
Comments
Post a Comment
Please do not enter any spam link in the comment box.