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
 
Line 2: Line 2:
  
 
== 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.
- Class names MUST be declared in `StudlyCaps`.
+
* Class names MUST be declared in <code>StudlyCaps</code>.
- Class names should be in the following format: `GO_<MODULENAME>_<FOLDERNAME>_<FILENAME>`
+
* Class names should be in the following format: <code>GO_<MODULENAME>_<FOLDERNAME>_<FILENAME></code>
- Class constants MUST be declared in all UPPER_CASE with underscore separators.
+
* Class constants MUST be declared in all UPPER_CASE with underscore separators.
- Method names MUST be declared in `camelCase`.
+
* Method names MUST be declared in <code>camelCase</code>.
- Property names MUST be declared in `camelCase`.
+
* Property names MUST be declared in <code>camelCase</code>.
- Property and Methods names MUST start with an initial underscore `_` if they are private.
+
* Property and Methods names MUST start with an initial underscore <code>_</code> if they are private.
- Always use `elseif` instead of `else if`.
+
* Always use `elseif` instead of <code>else if</code>.
- PHP code MUST use the long `<?php ?>` tags; it MUST NOT use the other tag variations such as `<?`.
+
* PHP code MUST use the long <code><?php ?></code> tags; it MUST NOT use the other tag variations such as <code><?</code>.
- In case file contains PHP only it should not have trailing `?>`.
+
* In case file contains PHP only it should not have trailing <code>?></code>.
- Do not add trailing spaces to the end of the lines.
+
* Do not add trailing spaces to the end of the lines.
  
 
== Docblocks ==
 
== Docblocks ==
Line 21: Line 21:
 
A block should at least contain a short description
 
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[]`
+
<code>@param</code>, <code>@var</code>, <code>@property</code> and <code>@return</code> must declare types as boolean, integer, string, array or null. You can use a class names as well such as <code>GO_Base_Data_Store</code> or <code>GO_Base_Db_ActiveRecord</code>. For a typed arrays use <code>GO_Base_Model_User[]</code>
  
When a function or class is depricated the `@deprecated` tag should be used (Netbeans can hide all deprecated functionality in the code completion)
+
When a function or class is deprecated the <code>@deprecated</code> tag should be used (Netbeans can hide all deprecated functionality in the code completion)
  
  
Line 31: Line 31:
  
 
The items of a model class should be in the following order:
 
The items of a model class should be in the following order:
- Constants (eg STATUS_OK, STATUS_FAILED)
+
* Constants (eg <code>STATUS_OK</code>, <code>STATUS_FAILED</code>)
- Properties/attributes (eg $_user, $amount)
+
* Properties/attributes (eg <code>$_user</code>, <code>$amount</code>)
- Overwritten functions (eg tableName(), primairyKey(), relations())
+
* Overwritten functions (eg <code>tableName()</code>, <code>primairyKey()</code>, relations()</code>)
- Get/Set Methods (eg getUser(), setEndTime($value))
+
* Get/Set Methods (eg <code>getUser()</code>, <code>setEndTime($value)</code>)
- Functions (eg start(), close(), addItem())
+
* Functions (eg <code>start()</code>, <code>close()</code>, <code>addItem()</code>)
  
If class name is not in the format `GO_<MODULENAME>_Model_<FILENAME>` not the the class will never be able to autoload
+
If class name is not in the format <code>GO_<MODULENAME>_Model_<FILENAME></code> not the the class will never be able to autoload
 
<MODULENNAME> MUST be in Firstcaps without special characters
 
<MODULENNAME> MUST be in Firstcaps without special characters
 
<FILENAME> MUST be StudlyCaps
 
<FILENAME> MUST be StudlyCaps
Line 43: Line 43:
 
== Controllers ==
 
== Controllers ==
  
All controllers should go into the `controller` folder of the module
+
All controllers should go into the <tt>controller</tt> folder of the module
  
 
The items of a controller class should be in the following order:
 
The items of a controller class should be in the following order:
  
- Properties ( eg `$layout`, `$model`)
+
* Properties ( eg. <code>$layout</code>, <code>$model</code>)
- Overwritten function (eg `beforeAction()`)
+
* Overwritten function (eg. <code>beforeAction()</code>)
- Actions (eg `actionSubmit($params)`, `actionStore($params)`)
+
* Actions (eg. <code>actionSubmit($params)</code>, <code>actionStore($params)</code>)
  
 
Controller action should only have one parameter named $parmas this is the http request its REQUEST array
 
Controller action should only have one parameter named $parmas this is the http request its REQUEST array
Line 59: Line 59:
  
  
## ExtJs Views
+
== ExtJs Views ==
  
All views should go into the `views/<theme>/` folder of the module
+
All views should go into the <code>views/<theme>/</code> folder of the module

Latest revision as of 14:20, 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 deprecated 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()</code>)
  • 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.


ExtJs Views

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