My Coding Standards
Please find below my coding standards that I apply to all my Magento and PHP projects to assure a high level of code quality. These rules will be updated permanently.
Backend
- Code sniffer rules available in vianetz/coding-standards Repository, which is based on Zend Coding Standards for PHP, PSR-1 and PSR-2
- Make use of static code analyzers like
phpstan
- Write unit tests
- PHPDoc Blocks are used whenever necessary and when they add explanation to the source code
- Settings that needs to be anonymized in staging or local development systems have been added to the anonymize script.
Magento
- Apply Magento coding standards
- All SQL updates (i.e. also CMS updates) are done via Magento setup scripts
- Custom settings are configured in separate customer-specific tabs in System -> Configuration, not in Magento default tabs
- All dependencies are handled via
composer
- Favor observers over rewrites
- Customer-specific Extensions (in customer namespace, e.g.
Vianetz\
) are created whenever required - Magento Extensions split the system into functional units that have a single responsibility and well-defined dependencies.
- A Magento Extension should model (part of) a single bounded context of the domain.
- Modules are natural units for code-ownership as well. Teams can be responsible for one or more modules in the system.
- Magento Core modifications or modifications to the source code of 3rd-party extensions are strictly prohibited
- Implement appropriate security measures
Frontend
- SASS preprocessor is used whenever possible
- Google Lighthouse Score above 95 in each category is targeted
- Avoid huge frameworks or libraries
- Prefer CSS utility classes
- Websites must be well accessible by screen readers (following rules of W3C)
Häufige Fragen
Unit-Tests für Eure Magento Extension ausführen
Siehe hier.
Wie wird die Qualität der Extension sichergestellt?
Jede neue Extension-Version wird automatisiert über unseren Build-Server erstellt. Dieser führt automatisch Unit-Tests, statische Code-Analysen und Integrationstest durch, im Anschluss wird die Version nach QA-Freigabe veröffentlicht.
Weitere Informationen haben wir hierzu in den Milestones zusammengefasst.