ApiOpenStudio adheres to the PSR-12 Extended coding style.
See PSR-12 for the full formal definition
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 \
includes/ \
public/*.php \
tests/api/ \
tests/runner_generate_db.php
A line of code should not exceed 120 characters.
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.
}
Standard PHPDOC rules apply.
Should be in the following format:
/**
* File description.
*
* @package ...
*/
Should be in the following format:
/**
* Short description.
*
* Long description(optional).
*
* @param type $var Parameter comment.
*
* @return type Comment.
*
* @throws ApiException Exception comment.
*/
Type hints are not required (to accommodate mixed types), but are recommended. The curly brackets must be on a new line.
e.g.:
public function functionName(string $a, int $b, $c)
{
}