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

Coding Guidelines

From Group-Office Groupware and CRM Documentation
Revision as of 13:10, 6 March 2013 by Admin (Talk | contribs) (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...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
  1. Coding Guidelines
    1. 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.

    1. 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)


    1. 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

    1. 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