Skip to content

Coding Standards

Raymond Feng edited this page Apr 16, 2021 · 4 revisions

Coding standards used for this project

Refer to this if you have any specific doubts of coding standards (with reference to PSR-1 and PSR-12): https://www.php-fig.org/psr

Code snippet examples:

  • File names - PascalCase with underscores to separate MVC typing.
    An exception for this is controllers, as these double as direct routes (i.e. Blog.php controller class will map to example.com/blog)
Utils.php
EnrollmentForm.php

// Notice that there is an underscore here, this is to separate out the fact that this class is a model
GoogleSheets_Model.php
  • Classes - PascalCase with underscores to separate MVC typing (and matching file name, one class per file)
  • Functions - camelCase
  • Variables - camelCase
  • Constants - UPPER_CASE

NOTE: We will reserve underscores in PHP functions to system functions (like mb_char(...))

/**
 * This is a PHPDocs comment (used for documentation).
 * 
 * @param string $customParameter
 * 
 * @return string
 */
public function exampleFunction($customParameter)
{
    // This is a comment
    $customStringVariable = "Hello, world!";
    return $customStringVariable;
}

Each function MUST have a PHPDoc style comment describing what the function does. Sentences should use correct grammar, i.e. full stops in the right places. Parameters and returned variables MUST have specified types.

If you have any doubts around correct usage, refer to older models (like GoogleSheets_Model.php)

Clone this wiki locally