I have been assigned to review Magento Code. What will be the best practices need to be considered.

2 Answers 2


Magento have a large docs you can follow

https://developer.adobe.com/commerce/php/coding-standards/ https://developer.adobe.com/commerce/php/best-practices/extensions/

PHP files must follow PSR-1/2 coding standard.

PHP files must start contains declare(strict_types=1);

You must use dependency injection instead of using the object manager (object manager is deprecated) Read more about it here

In *.phtml files when you want to display informations you must use an escaper

\Magento\Framework\Escaper $escaper

<?= $escaper->escapeHtml(__('The string you need to translate'))?>

For translation you can follow thoose guide lines

In addition you can review the code with phpstorm and add the extension 'Magento PhpStorm' it will help you to do lot of things described here

If you need more informations feel free to ask

  • Thanks, I will validate the code as per given criteria. Commented Jul 5, 2023 at 11:31
  1. Code Standards and Conventions: Check if the code follows Magento coding standards and best practices. This includes naming conventions, file structure, indentation, proper commenting, and adherence to the Magento coding style guide.

  2. Security Considerations: Verify that security best practices are followed, such as protecting against SQL injection, cross-site scripting (XSS), and ensuring sensitive data handling is done securely.

  3. Performance Optimization: Assess the code for any performance bottlenecks or inefficiencies. Look for unnecessary database queries, inefficient loops, excessive memory usage, and potential areas for optimization.

  4. Module Structure and Organization: Examine the structure and organization of modules. Check if the code follows a modular approach, with proper separation of concerns, reusable components, and clear module boundaries.

  5. Error Handling and Exception Management: Ensure that proper error handling and exception management practices are implemented. Validate input data, handle exceptions gracefully, and log errors appropriately to facilitate debugging and troubleshooting.

  6. Database Operations: Review database interactions and ensure they are efficient and follow Magento's best practices. Check for proper use of models, resource models, and collections. Avoid direct SQL queries whenever possible.

  7. Code Reusability and Modularity: Evaluate if the code is modular, reusable, and follows the principles of object-oriented programming (OOP). Look for opportunities to refactor repetitive code into reusable functions or classes.

  8. Magento API Usage: Check if the code adheres to Magento's API usage guidelines. Verify that Magento's core classes and methods are used correctly and that custom code integrates properly with the Magento ecosystem.

  9. Testing and Quality Assurance: Assess if the code has been adequately tested, including unit tests, integration tests, and functional tests. Verify the code coverage and the quality of test cases.

  10. Documentation: Check if the code is well-documented, including inline comments, class-level and method-level PHPDoc comments, and clear explanations of complex or non-obvious code segments.

  11. Extension Compatibility: Evaluate the code for compatibility with other installed extensions, ensuring that it does not introduce conflicts or compatibility issues.

  12. Magento Upgradability: Consider if the code changes may impact future Magento upgrades. Ensure that modifications are made in a way that facilitates smooth upgrades without causing conflicts or breaking changes.

Refer URLs:-
https://developer.adobe.com/commerce/php/best-practices/extensions/ https://inchoo.net/magento-2/magento-coding-standards/

  • Thanks, I will validate the code as per given criteria. Commented Jul 5, 2023 at 11:31

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.