6.4. Coding standards

ApiOpenStidio adheres to the PSR-12 Extended coding style.

See PSR-12 for the full formal definition

6.4.1. Codesniffer

The GitLab pipelines runner will run phpcs against any commit or merge resquest. Any Merge request or commit that fails the phpcs test will not be accepted. So it is worth running phpcs locally before any commit.

php_codesniffer will be installed by composer. The standard used is PSR12.

After composer install has run, the following command will test your code locally:

$ ./vendor/bin/phpcs --standard=PSR12 --report-file=phpcs.txt includes/ public/*.php tests/api/ tests/_support/Helper/ tests/runner_generate_db.php

6.4.2. Line length

A line of code should not exceed 120 characters.

6.4.3. Variables

  • Local variables should be camel case.
  • Class names should be camel case and begin with a capital letter.
  • Class methods should be camel case and begin with a lower case letter.

6.4.4. Processors

  • machine names should be snake case.
  • names should be upper case first.

6.4.5. Database

  • Table names should be snake case.
  • Column names should be snake case.

6.4.6. Arrays

  • Use the short syntax of [] instead of array().

6.4.7. Constants

  • all constants and reserved constants (e.g. true, false, null) should be in lower case.

6.4.8. Get and Post parameters

  • get and post params should be in snake case.

6.4.9. Try/catch and if/else

The following curly brackets should not be on a new line. e.g.:

if (a == b) {
    // Do something.
} else {
    // Do something else.

try {
    // Do something.
} catch(Excption $e) {
    // Handle the expection.

6.4.10. PHPDOC

Standard PHPDOC rules apply. file comment

Should be in the following format:

 * File description.
 * @package ...
 */ Function comments

Should be in the following format:

 * Short description.
 * Long description(optional).
 * @param type $var Parameter comment.
 * @return type Comment.
 * @throws ApiException Exception comment.
 */ Function declarations

Type hints are not required (to accommodate mixed types), but are recommended. The curly brackets must be on a new line.


public function functionName(string $a, int $b, $c)