Coding standards
Code writing
The file format for all files is to be set to the UNIX file format (no ^M at the end of each line).
Indentation
-
1 tab = 3 spaces
- tabs are to be expanded as spaces: vim cofiguration is
set tabstop=3
set expandtab
set shiftwidth=3
Braces
-
Always start ‘{‘ on a new line:
if ($condition)
{
...
}
else
{
...
}
Arrays
Always add a coma ad the end of an array, even if there is no additional elements
$myarray = array(
'elem1' => val1,
'elem2'=> val2,
);
Naming conventions
Class Names/File Names
-
Always start a file using the tag below since it is the most portable way to include PHP code on different operating systems and setups.
<?php
-
Class name should start with a capital letter followed by camel case
class EntityFramework
{
} - Classes should be placed in a file called class.ClassName.inc.php
- Where a file has more than one class in it, then the other classes defined in the file MUST be tightly related to one main class in the file; and the file named after that class
- Exception for egroupware compatibility:
- the prefix ui_ , bo_ , so_ , hooks_ , ajax_ui_ are to be used where required
- Egroupware widget follow the naming convention AppName_WidgetName_widget
- Egroupware applications names follow the lower case, underscore separated naming convention blue_admin etc.
Method/Function name
- Class constructor shall all be called __construct
-
Start a method name with a lower case followed by camel case
function getName()
{
(...)
} - member variables follow the same convention
- the use of an access qualifier for classes method and members is compulsory: 'public' 'protected' or 'private'
Comments
-
Use ‘/* */’ for longer comments and ‘//’ for shorter ones
Table names for database
- Table name are to be in lower case words separated by "_"
- The first part of the name is the application name
- The second part of the name is the entity
blue_order_recurring_data for entity blue_order.RecurringData
Database fields
- fields referring to another object via their id shall follow the convention
objectname_id
SVN commit messages
- If applicable, specify the module/application name first. For example, if it is only changes on an application called blue_admin, the commit messages should look like:
blue_admin: my commit message here...
Localisation and user preferences
Good practices in the code should be taken so that the resulting application is easy to localize, and so that the user can choose some formats such as dates and currencies. The following is to be followed:
- Use the lang function for all messages sent back to the user. For instance:
$msg .= lang('An error occured in entity %1', $entity)
- Use the 'Date' widget for displaying all dates
- Use the 'Formatted number' widget for displaying all currency amounts
BlueErp