PHP coding standard

The core development team uses the Magento Coding Standard. We recommend that developers who create extensions and customizations also use this standard.

The Magento Coding Standard provides a set of rules that covers the following:

Coding standard compliance

Developers should consistently use PHP_CodeSniffer to enhance the readability of the code and ensure that it meets the Magento Coding Standard. PHP_CodeSniffer is the most popular tool in use throughout the PHP development community. It provides the mechanism of checking code compliance with specific coding standard.

The set of rules is located in ruleset.xml file of the Magento Coding Standard.

Learn more about using rule sets with PHP CodeSniffer ruleset

Literal Namespace Rule

For class name resolution, use the ::class keyword instead of a string literal for every class name reference outside of that class. This includes references to:

Examples:

  $this->get(ClassName::class);
  $this->get(\Magento\Path\To\Class::class);

The coding standards overview introduces Adobe Commerce and Magento Open Source-specific practices for PHP, JavaScript, and JQuery.