This manual is deprecated. Please visit https://groupoffice.readthedocs.io for the latest documentation.

Difference between revisions of "Coding Guidelines"

From Group-Office Groupware and CRM Documentation
Jump to: navigation, search
(Created page with "# Coding Guidelines ## Coding style - Files MUST use only UTF-8 without BOM for PHP code. - Code MUST use tabs for indenting, not spaces. - Class names MUST be declared in `Stud...")
 
Line 1: Line 1:
# Coding Guidelines
+
= Coding Guidelines=
  
## Coding style
+
== Coding style ==
 
- Files MUST use only UTF-8 without BOM for PHP code.
 
- Files MUST use only UTF-8 without BOM for PHP code.
 
- Code MUST use tabs for indenting, not spaces.
 
- Code MUST use tabs for indenting, not spaces.
Line 15: Line 15:
 
- Do not add trailing spaces to the end of the lines.
 
- Do not add trailing spaces to the end of the lines.
  
## Docblocks
+
== Docblocks ==
  
Every declared class or function should contain a docblocks header with exception of overwritten function that do not add new functionality (eg `tableName()`, `relations()`)
+
Every declared class or function should contain a docblocks header with exception of overwritten function that do not add new functionality (eg <code>tableName()</code>, <code>relations()</code>)
  
 
A block should at least contain a short description
 
A block should at least contain a short description
Line 26: Line 26:
  
  
## Models
+
== Models ==
  
 
All models should go into the `model` folder of the module folder
 
All models should go into the `model` folder of the module folder
Line 41: Line 41:
 
<FILENAME> MUST be StudlyCaps
 
<FILENAME> MUST be StudlyCaps
  
## Controllers
+
== Controllers ==
  
 
All controllers should go into the `controller` folder of the module
 
All controllers should go into the `controller` folder of the module

Revision as of 14:13, 6 March 2013

Coding Guidelines

Coding style

- Files MUST use only UTF-8 without BOM for PHP code. - Code MUST use tabs for indenting, not spaces. - Class names MUST be declared in `StudlyCaps`. - Class names should be in the following format: `GO_<MODULENAME>_<FOLDERNAME>_<FILENAME>` - Class constants MUST be declared in all UPPER_CASE with underscore separators. - Method names MUST be declared in `camelCase`. - Property names MUST be declared in `camelCase`. - Property and Methods names MUST start with an initial underscore `_` if they are private. - Always use `elseif` instead of `else if`. - PHP code MUST use the long `<?php ?>` tags; it MUST NOT use the other tag variations such as `<?`. - In case file contains PHP only it should not have trailing `?>`. - Do not add trailing spaces to the end of the lines.

Docblocks

Every declared class or function should contain a docblocks header with exception of overwritten function that do not add new functionality (eg tableName(), relations())

A block should at least contain a short description

`@param`, @var, `@property` and `@return` must declare types as boolean, integer, string, array or null. You can use a class names as well such as `GO_Base_Data_Store` or `GO_Base_Db_ActiveRecord`. For a typed arrays use `GO_Base_Model_User[]`

When a function or class is depricated the `@deprecated` tag should be used (Netbeans can hide all deprecated functionality in the code completion)


Models

All models should go into the `model` folder of the module folder

The items of a model class should be in the following order: - Constants (eg STATUS_OK, STATUS_FAILED) - Properties/attributes (eg $_user, $amount) - Overwritten functions (eg tableName(), primairyKey(), relations()) - Get/Set Methods (eg getUser(), setEndTime($value)) - Functions (eg start(), close(), addItem())

If class name is not in the format `GO_<MODULENAME>_Model_<FILENAME>` not the the class will never be able to autoload <MODULENNAME> MUST be in Firstcaps without special characters <FILENAME> MUST be StudlyCaps

Controllers

All controllers should go into the `controller` folder of the module

The items of a controller class should be in the following order:

- Properties ( eg `$layout`, `$model`) - Overwritten function (eg `beforeAction()`) - Actions (eg `actionSubmit($params)`, `actionStore($params)`)

Controller action should only have one parameter named $parmas this is the http request its REQUEST array Controllers that will return JSON data should extend `GO_Base_Controller_AbstractJsonController`

Prevent using properties in a class, an action method is 1 script run

Prevent private methodes, use them for code that should be shared among actions. In must cased there is code in the controller that is functionality of a class.


    1. ExtJs Views

All views should go into the `views/<theme>/` folder of the module