19. Operators
All binary operators (operators that come between two values), such
as +, -, =, !=, ==, >, etc. should have a space before and after the
operator, for readability.
20. Casting
Put a space between the (type) and the $variable in a cast:
(int) $mynumber.
23. Line length
and wrapping
In general, all lines of code should not be longer than 80 chars.
Lines containing longer function names, function/class definitions,
variable declarations, etc are allowed to exceed 80 chars.
Control structure conditions may exceed 80 chars, if they are
simple to read and understand.
Conditions should not be wrapped into multiple lines.
24. Function Calls
Functions should be called with no spaces between the function
name, the opening parenthesis, and the first parameter; spaces
between commas and each parameter, and no space between the
last parameter, the closing parenthesis, and the semicolon.
26. Class
Constructor Calls
When calling class constructors with no arguments, always include
parentheses. This is to maintain consistency with constructors that
have arguments.
27. Arrays
Arrays should be formatted with a space separating each element
(after the comma), and spaces around the => key association
operator.
30. Semicolons
The PHP language requires semicolons at the end of most lines, but
allows them to be omitted at the end of code blocks. Drupal coding
standards require them, even at the end of code blocks.
33. Naming Conventions:
Naming Conventions:
Functions
and variables
Functions and variables should be named using lowercase, and words
should be separated with an underscore. Functions should in
addition have the grouping/module name as a prefix, to avoid name
collisions between modules.
34. Naming Conventions:
Naming Conventions:
Persistent
Variables
Persistent variables (variables/settings defined using Drupal's
variable_get()/variable_set() functions) should be named using all
lowercase letters, and words should be separated with an
underscore. They should use the grouping/module name as a prefix,
to avoid name collisions between modules.
35. Naming Conventions:
Naming Conventions:
Constants
Constants should always be all-uppercase, with underscores to
separate words. (This includes pre-defined PHP constants like TRUE,
FALSE, and NULL.)
Module-defined constant names should also be prefixed by an
uppercase spelling of the module that defines them.
In Drupal 8 and later, constants should be defined using the const
PHP language keyword (instead of define()), because it is better for
performance. Ex: <?php const CACHE_TEMPORARY = -1; ?>
36. Naming Conventions:
Naming Conventions:
Global Variables
If you need to define global variables, their name should start with
a single underscore followed by the module/theme name and
another underscore.
38. Naming Conventions:
Naming Conventions:
File names
All documentation files should have the file name extension ".txt"
to make viewing them on Windows systems easier. Also, the file
names for such files should be all-caps (e.g. README.txt instead of
readme.txt) while the extension itself is all-lowercase (i.e. txt
instead of TXT).
40. Helper Modules:
Helper Modules:
Coder
Using PHP_Codesniffer, Coder includes “Coder Review” module that
can be use to check the Drupal coding standard of your custom
modules, themes, css, and javascript.
46. DevOps
Loves
Automation
If you're using version control, you can take advantage the “ hook”
feature in automating all reviews. You can combine
Bash/PHP/Perl/Python script, Drush, and Coder to do the job.
49. Deployment:
Deployment:
Configuration
Management
Enables the ability to keep track of specific configurations on a
Drupal site, provides the ability to move these configurations
between different environments (local, dev, qa, prod), and also
move configurations between completely different sites (migrate
configurations) without the use of modules with all configuration
being owned by the site.
53. Security:
Security:
Security Team
Perform analysis of core or contributed project code.
Resolve reported security issues in a Security Advisory.
Provide assistance for contributed module maintainers in resolving
security issues.
Provide documentation on how to write secure code.
Provide documentation on securing your site.
58. Caching:
Caching:
Boost
Boost provides static page caching for Drupal enabling a very
significant performance and scalability boost for sites that receive
mostly anonymous traffic. For shared hosting this is your best option
in terms of improving performance.