The Drupal community has defined a set of coding standards and best practices that you should adhere to whenever you're writing code for Drupal. These standards provide a set of rules for how your code should be formatted, and best practice guidelines for naming conventions and the location of files. This ensures consistency in code throughout the project and makes it easy for developers to move around from one sub-section to another without having to re-learn how to read the code.
- Automate coding standards compliance for code
- Properly use the t() function to make strings translatable in code
This is a well-defined area that does not tend to change quickly or dramatically.
Official community coding standards (Drupal.org)
- This is the official, canonical source for community coding standards and should be a regular reference.
Coder Sniffer module documentation (Drupal.org)
- Learn how to install and use Coder Sniffer to automatically check your code for standards compliance. Works as a standalone command or in conjunction with many IDEs.
PhpStorm Coder and PHP CodeSniffer integration (jetbrains.com)
- Learn how to configure PhpStorm to help you comply with Drupal coding standards.
Configuring Sublime Text (Drupal.org)
- Learn how to configure Sublime Text to help you comply with Drupal coding standards.
DrupalCon Baltimore 2017: Code Standards: It's Okay to be Yourself (youtube.com)
- Presentation covering both the coding standards, and why adhering to them is a good idea.
Install Drupal Coder and PHP CodeSniffer to your Drupal project to lint PHP code (jeffgeerling.com)
- Jeff shows how to install these tools as dev dependencies using Composer, instead of globally on your system. He also talks about his CI/CD integration task that runs phpcs.