HomeDocumentationTutorialsCoding Standards

Coding Standards

Coding Standards

Adhering to a consistent coding standard is crucial for maintaining code readability, reducing errors, and ensuring smooth collaboration among team members. This tutorial outlines the coding standards for file naming, directory structure, database table naming, and coding conventions.

 

File Naming Conventions

General Rules:

  • All file names must be in lowercase.
  • No spaces are allowed; use hyphens (-) instead.
  • Underscores (_) should not be used.

Specific File Types:

  • Cascading Stylesheets: File names must end with .css.
  • Example: main-styles.css
  • Template UI/UX Files: File names must end with .tpl.
  • Example: header-template.tpl
  • Language Files: File names must end with .xml.
  • Example: en.xml
  • Class Files:  Class names can use uppercase for the first letter and each subsequent word.
  • Example: UserModel.php

Database Table Naming

General Rules:

  • Table names must be in singular form.
  • All table names must be in lowercase.
  • Use underscores (_) to separate words.
SQL
CREATE TABLE member (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL
);
 
CREATE TABLE member_comment (
    id INT AUTO_INCREMENT PRIMARY KEY,
    member_id INT NOT NULL,
    comment TEXT NOT NULL
);

The tables in the database should have the id as a primary key, and the following fields should be included at the end of  each table:

  • status_id
  • created_by
  • created_date
  • modified_by
  • modified_date

These are called control fields and are automatically handled by the framework for tracking purposes.

NOTE: All table column/field names should be not more than 31 characters in length

for the detailed database structure, please refer to the Database Dictionary Document.

Adapter Structure

General Rules:

  • Adapters go inside a folder called adapters in the root directory.
  • Each adapter folder is named after the service, all in lowercase and separated by hyphens.
    • Example: sms-company
  • The file name for the interface must include the name of the interface followed by the word interface.
    • Example: /adapters/sms-company/sms-company.interface.php
  • The structure of an adapter must be a class named according to the class standard.
    • Example: SmsCompanyProvider

File: adapters/sms-company/sms-company.interface.php

 

 

Webservice Structure

General Rules:

  • Webservice names must be camelCased starting with an uppercase name of the service as configured in the service management.
    • Example: PaymentService
  • Each method of the webservice must be prefixed with the service name followed by .methodName.
    • Example: PaymentService.processTransaction.php
  • The webservice method must be camelCased starting with a lowercase letter.

 PaymentService.processTransaction.php

PHP
/**
* @ desc payment service for all transactions
*
* @ param int $parameter1
* @ param string $parameter2
* @ param boolean $parameter3 optional
* @ param mixed $parameter4 optional
*
* @ throws SoapFault
* @ return object SimpleXMLElement / JSON String
* @ exceptions throw SoapFault exception on error
**/
function processTransaction($parameter1, $parameter2, $parameter3= null, $parameter4 = null) {
 // implement your function
}

 

 

function processTransaction($parameter1, $parameter2, $parameter3 = null, $parameter4 = null) {

    // Implementation

}

php##

 

Important to note:

  • The parameters of the web service must have the data type defined i.e. int, string, Boolean, mixed
  • The options parameters must have the work optional after the variable name
  • Optional parameters must be defined at the end of the parameter list, after any required parameters.  
  • The validation of parameters from data send will be validated by the framework
  • The web service client is not obliged to follow the exact sequence of the parameters.

 

Coding Conventions

Static Methods:

Static methods must include the word static in their names.

PHP
class ClassName{
    public static function getMethod($a, $b) {
        return $a + $b;
    }
}

 

Constant Variables:

Constant variables must be in uppercase.

Use underscores (_) for word separation.

PHP
define('USER_DIRECTORY_NAME', '/path/to/user/directory');
const MAX_UPLOAD_SIZE = 1048576; // 1MB in bytes

 

By following these standards, your codebase will remain clean, consistent, and easy to maintain. Ensure all team members are familiar with these rules and apply them consistently in their work.