meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
develop:codingstyle [2012/12/13 18:44] – [SQL Queries] michiel | develop:codingstyle [2016/11/16 14:29] (current) – Removed rules already covered by PSR1&2; Removed reference to API docs; Removed requirement for stating function author; Made @param and @return mandatory samtuke | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Coding Style ====== | ||
+ | phpList follows the coding standards of PHP-FIG [[http:// | ||
+ | |||
+ | All changes to the phpList 3 and phpList 4 codebases must adhere to the coding standards. You are only responsible for the lines that you edit. | ||
+ | |||
+ | phpList 3 does not uniformly follow the above standards as it is an older codebase not fully renewed. phpList 4 already adheres to these standards. | ||
+ | |||
+ | ===== SQL Queries ===== | ||
+ | |||
+ | Build the query using '' | ||
+ | |||
+ | < | ||
+ | $query = sprintf(' | ||
+ | $result = Sql_Query($query); | ||
+ | </ | ||
+ | |||
+ | Explicitly mention the columns in the result set and do not use wildcards. So, that means queries like | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | Also, have a look in the mysql.inc file for the functions that abstract the Mysql calls. Use the ones in there, and do not use any ''" | ||
+ | |||
+ | You can use '' | ||
+ | |||
+ | All tables are referenced using the global '' | ||
+ | |||
+ | ====== Language and translation ====== | ||
+ | |||
+ | When you output strings, use the function '' | ||
+ | |||
+ | < | ||
+ | print s(' | ||
+ | </ | ||
+ | |||
+ | The '' | ||
+ | |||
+ | < | ||
+ | print s(' | ||
+ | </ | ||
+ | ((I actually need to check that this is processed correctly by POedit)) | ||
+ | |||
+ | ===== Obsolete coding style ===== | ||
+ | |||
+ | A lot of code still has these styles, but should be redone. Try to change it whenever you touch a certain section of the code where this is used. But be careful to ensure it doesn' | ||
+ | |||
+ | * if ($variable) | ||
+ | This should be changed to '' | ||
+ | |||
+ | * Queries that look like ''" | ||
+ | These should be redone using the sprintf format as mentioned above. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== Commenting ===== | ||
+ | |||
+ | Each function and class should have a PHPDocumentor style comment, giving at least the function' | ||
+ | |||
+ | Example: | ||
+ | |||
+ | <code php> | ||
+ | /** | ||
+ | * Check for foo in bar | ||
+ | * | ||
+ | * Checks if there is a foo in bar | ||
+ | * | ||
+ | * @author | ||
+ | * @param | ||
+ | * @return | ||
+ | * | ||
+ | */ | ||
+ | function is_foo($in) { | ||
+ | ... | ||
+ | } | ||
+ | </ |