Follow defined coding standards
New code is encapsulated in Classes
In ME, PHP classes that are potentially reusable can be placed in
Code must be human-readable
Use meaningful variable and function names
Code must be properly indented
Code must be cleaned and organized
Massive files of code must be logically broken down
Form submission handling should never be in the same file as the form itself
Giant if/switch statements with all sorts of cases within are not allowed
Any non-trivial methods should have unit tests
Any method that contains significant logic should have a test for that logic. A getter or setter, for example, does not need a test. A method that manipulates data from a database may require a mock, but can you separate the database functionality from the manipulation?
Functions and classes require a comment block
Add doc comment blocks, e.g. PHP Doc blocks, for your code (not necessary for getters and setters). Explain what the code does: what, how and why. Give examples of usage where it is helpful.
No "magic" numbers or strings
Do not use non explained numeric or string values in your logic. Use
define() for constants or declare them as class constants
Code does not have duplicated blocks
Extract code into a function and call it where needed
Functions should have a single responsibility
Any function you write should do one thing, and one thing only. Break down your code to multiple functions, and for medium/large features, create classes to encapsulate a process or a pattern
Lines should be entirely visible on a typical editor screen
Wrap your code appropriately
Avoid more than 3 levels of nested control structures
Move code to separate functions
Function names reflect their purpose and usage
A well-chosen function name can avoid the necessity of commenting what the function is doing, e.g.
// Sum up the ages of members
$age_sum = processMembers($part);
$age_sum = sumMemberAges($part);
Functions should not have more than 5 parameters
Pass values in an associative array or object
Variables should have the tightest scope possible
Declare variables inside the block where they are used.
Remove commented-out code
If code is not needed, remove it. Other developers will not know why it is there. Deleted code can always be retrieved using
Remove all @todo statements
Resolve any @todo items, or remove them. Work that needs to be done should be described in a Jira ticket.
Functions must be as reusable as possible
Try not to rely on globals. Pass in (inject) the data that is needed.
Use strict comparisons where possible
=== to test type equality as well as values, so that the language doesn't do under-the-hood type conversions that may not work as expected.
All resources must exist in the Elentra source tree. Do not call external JS or CSS files.
In the core product, do not reference files via CDN or other external sources.
Variable validation checks for daisy-chained method calls
Ensure that method calls are from the valid object before calling them. Daisy Chaining might cause a show stopper error when the object is really a boolean from ADODB
Do not use
document.createElement to create form elements in ME
All form elements must be created in the PHP template, and then manipulated via JS/jQuery.
If you are looking for something more robust, consider using
mustache.js (bundled in ME), or even better, write your feature in EJS2