- Magento 2 Architecture Layers
- Magento 2 Application Modes
- Magento 2 Areas
- Magento 2 Request Flow
- Magento 2 Coding Standard
Coding standards are a result of conventions designed to produce high-quality code. Adopting certain standards yields better code quality, reduces the time taken to develop, and minimizes maintenance cost. Following coding standards requires knowing the standards in question and meticulously applying it to every aspect of the code that we write.
Use Magento’s coding standards when you contribute to Magento’s codebase or create extensions:
- The code demarcation standard: decoupling HTML, CSS and JS from PHP classes. By doing so, the backend related development stays unaffected by frontend development (and vice versa). This means that we can make business logic changes without fearing a broken frontend. Details
- The PHP coding standard: refers to a set of rules that covers the following:
- PSR-1 and PSR-2 compliance. PSR-1: Basic Coding Standard touches on PHP filenames, class names, namespaces, class constant, properties, and methods. PSR-2: Coding Style Guide extends the PSR-1 by touching on the actual inners of a class, such as spaces, braces, method and properties visibility, control structures, and so on.
- The use of insecure functions
- Unescaped output
- The use of deprecated PHP functions
- PHP code syntact
- Naming convention
- The use of PHP superglobals
- Empty code blocks
- Improper exception handling
- Raw SQL queries and many other general PHP and Magento-specific code issues
To ensure that the code meets the standard, developers are recommended to use PHP_CodeSniffer. This tool provides the mechanism of checking code compliance with specific coding standard.
- The jQuery widget coding standard: mandatory for Magento core developers and recommended for third-party developers. It goes without saying how important jQuery UI widgets are in Magento. The standard describes several things, such as widget naming, instantiation, extension, DOM event bubbling, and so on.
- The DocBlock standard: defines the requirement and conventions for addition of inline code documentation. The goal of this standard is to unify usage of code DocBlocks for all files, not specific to a particular language. However, a DocBlock standard for that particular language may override it.
- The LESS coding standard: defines the formatting and coding style when working with LESS and CSS files.
You can read more about the actual details of each standard at http://devdocs.magento.com.