Minimum Version: 7.2

For PHP, we use a foundation of PSR-1 and PSR-12, with some slight modifications on code structure and naming conventions. These customizations are shown below.

Linting Code

We use a custom standard for the phpcs tool, available at Submitty/submitty-php-codesniffer. You can lint your code, assuming that you are in site/ by doing:

vendor/bin/phpcs --standard=tests/ruleset.xml [path/to/file/or/directory]

where if you leave off the path, it will analyze all files and directories for Submitty.

Additionally, you can apply the automatic fixer to your code by running:

vendor/bin/phpcbf --standard=tests/ruleset.xml [path/to/file/or/directory]

where this can fix a large range of possible PHPCS style errors, though some may require manual intervention.

Classes, Methods

class Test {
    public function foo() {
        // code
    }

    public function method(
        $long_arg_name_1,
        $another_long_name,
        $third_long_name
    ) {
        // code
    }
}

Control Structures

if ($foo) {
    // code
}
elseif ($bar) {
    // code
}
else {
    // code
}
do {
    // code
} while ($foo);

Naming Conventions