Magento Coding Practices
Application skill for Adobe Commerce / Magento Open Source coding standards ingest (awesome-guidelines). Generic PHP: php-coding-practices. Security depth: webappsec-coding-practices. Sibling CMS: drupal-coding-practices, wordpress-coding-practices.
Core Principle
Magento extension quality is PSR-12 mechanics plus Magento2 PHPCS security sniffs plus technical-guideline architecture, strict typed PHP, interface DI and composition, layered service contracts, sanitize/escape discipline, and static analysis in CI.
When to Use / NOT
- Adobe Commerce / Magento Open Source modules under
app/code/Vendor/Module.
- Reviewing
di.xml, *Api interfaces, controllers, blocks, .phtml, module JS.
- Setting up PHPCS
Magento2, ESLint, PHPMD in extension CI.
NOT when:
- Non-Magento PHP,
php-coding-practices.
- WordPress/Drupal, sibling CMS practice skills.
- Core platform refactors spanning entire Magento tree, follow Adobe core contribution process.
- Hyvä/headless frontends only, still apply API/security rules; JS/CSS guides may differ.
Workflow
- PHP/types, strict_types, return types,::class (
magento-style-php-types.md).
- Class/DI, composition, constructors, di.xml (
magento-style-class-di.md).
- Security/exceptions, SQL, XSS, superglobals, exceptions (
magento-style-security-exceptions.md).
- Layers/verify, Api modules, docblocks, PHPCS (
magento-style-layers-verify.md).
Red Flags
- New PHP file missing
declare(strict_types=1);
- String literal class name instead of
::class
- Missing return type on new public method
$_GET / $_POST / $_SERVER in module code
- Unescaped output in PHP (outside vetted
.phtml patterns)
- Public
init() or business logic in constructor
- Concrete adapter type-hinted in constructor instead of interface
- Deep inheritance for code reuse
- Raw SQL with interpolated variables
- Swallowed exception without logging
- Generic
\Exception thrown from controller
- Stateful plugin or plugin on data object
- Object instantiation inside
.phtml template
- PHPCS Magento2 errors on changed extension paths
Verification
vendor/bin/phpcs --standard=Magento2 app/code/Vendor/Module on changed paths
vendor/bin/phpcbf --standard=Magento2 for auto-fixable sniffs
- ESLint with magento-coding-standard config on changed JS
- PHPMD project ruleset when available
- DocBlock spot-check on new public API
- di.xml preference/plugin review for new services
References
awesome-guidelines/references/magento-style-learning-note.md
awesome-guidelines/references/magento-style-php-types.md
awesome-guidelines/references/magento-style-class-di.md
awesome-guidelines/references/magento-style-security-exceptions.md
awesome-guidelines/references/magento-style-layers-verify.md
Related skills
php-coding-practices, PSR baseline outside Magento
webappsec-coding-practices, broader secure coding patterns
symfony-coding-practices, DI/Yoda patterns in Symfony stacks (contrast)
drupal-coding-practices, sibling CMS conventions
wordpress-coding-practices, sibling CMS conventions
1---2name: magento-coding-practices3description: Use when authoring or reviewing Adobe Commerce/Magento extensions, strict_types, PSR-12,::class, DI/composition, prepared SQL, escape output, service contracts, and PHPCS Magento2 verification.4---56# Magento Coding Practices78Application skill for Adobe Commerce / Magento Open Source coding standards ingest (`awesome-guidelines`). Generic PHP: `php-coding-practices`. Security depth: `webappsec-coding-practices`. Sibling CMS: `drupal-coding-practices`, `wordpress-coding-practices`.910## Core Principle1112Magento extension quality is **PSR-12 mechanics plus Magento2 PHPCS security sniffs plus technical-guideline architecture**, strict typed PHP, interface DI and composition, layered service contracts, sanitize/escape discipline, and static analysis in CI.1314## When to Use / NOT1516- Adobe Commerce / Magento Open Source modules under `app/code/Vendor/Module`.17- Reviewing `di.xml`, `*Api` interfaces, controllers, blocks, `.phtml`, module JS.18- Setting up PHPCS `Magento2`, ESLint, PHPMD in extension CI.1920**NOT when:**2122- Non-Magento PHP, `php-coding-practices`.23- WordPress/Drupal, sibling CMS practice skills.24- Core platform refactors spanning entire Magento tree, follow Adobe core contribution process.25- Hyvä/headless frontends only, still apply API/security rules; JS/CSS guides may differ.2627## Workflow28291. **PHP/types**, strict_types, return types,::class (`magento-style-php-types.md`).302. **Class/DI**, composition, constructors, di.xml (`magento-style-class-di.md`).313. **Security/exceptions**, SQL, XSS, superglobals, exceptions (`magento-style-security-exceptions.md`).324. **Layers/verify**, Api modules, docblocks, PHPCS (`magento-style-layers-verify.md`).3334## Red Flags3536- New PHP file missing `declare(strict_types=1);`37- String literal class name instead of `::class`38- Missing return type on new public method39- `$_GET` / `$_POST` / `$_SERVER` in module code40- Unescaped output in PHP (outside vetted `.phtml` patterns)41- Public `init()` or business logic in constructor42- Concrete adapter type-hinted in constructor instead of interface43- Deep inheritance for code reuse44- Raw SQL with interpolated variables45- Swallowed exception without logging46- Generic `\Exception` thrown from controller47- Stateful plugin or plugin on data object48- Object instantiation inside `.phtml` template49- PHPCS Magento2 errors on changed extension paths5051## Verification5253- `vendor/bin/phpcs --standard=Magento2 app/code/Vendor/Module` on changed paths54- `vendor/bin/phpcbf --standard=Magento2` for auto-fixable sniffs55- ESLint with magento-coding-standard config on changed JS56- PHPMD project ruleset when available57- DocBlock spot-check on new public API58- di.xml preference/plugin review for new services596061## References6263- `awesome-guidelines/references/magento-style-learning-note.md`64- `awesome-guidelines/references/magento-style-php-types.md`65- `awesome-guidelines/references/magento-style-class-di.md`66- `awesome-guidelines/references/magento-style-security-exceptions.md`67- `awesome-guidelines/references/magento-style-layers-verify.md`6869## Related skills7071- `php-coding-practices`, PSR baseline outside Magento72- `webappsec-coding-practices`, broader secure coding patterns73- `symfony-coding-practices`, DI/Yoda patterns in Symfony stacks (contrast)74- `drupal-coding-practices`, sibling CMS conventions75- `wordpress-coding-practices`, sibling CMS conventions