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.
General Rules:
Specific File Types:
General Rules:
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:
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.
General Rules:
File: adapters/sms-company/sms-company.interface.php
General Rules:
PaymentService.processTransaction.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:
Static Methods:
Static methods must include the word static in their names.
class ClassName{
public static function getMethod($a, $b) {
return $a + $b;
}
}
Constant Variables:
Constant variables must be in uppercase.
Use underscores (_) for word separation.
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.
Your download is here.