Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents
maxLevel2

PHP


Info

The implementation of this coding standard is on going. As the Rogo code base is some 18 years old the code base will take some time to be fully compliant. Contributors should focus on their own changes being compliant. If they would like to help making the older code compliant that would be appreciated.

CodeSniffer


It is recommended you set up your IDE to style check using code sniffer.

...

Note

auto test not currently set-up to analyse pull requests


PSR12


All PHP code should comply to the PSR12 standard with the exception of the following :exceptions.


Exceptions to PSR12

Namespaces/Classes

  • Each class must be in a file by itself
  • Each class must be in a namespace of at least one level (a top-level vendor name)

...

Some existing classes do NOT follow PSR-0 so code sniffer will warn about it. However, new files will be expected to follow this standard and we should attempt to update existing code where possible.

Constants

  • Visibility must be declared on all constants as Rogo supports PHP 7.2 as a minimum

Strings

  • Variables are not allowed in double quoted string, concatenation should be used instead
  • String that do not require double quotes should use single quotes instead
  • Multi-line strings concatenations should should align 4 spaces indentation from the first line e.g.


    Code Block
    languagephp
    $string = 'a string '
        . 'a concat'
        . 'another concat';


...

Some existing strings use double quotes when not necessary and so code sniffer will warn about it. However, new files will be expected to follow this and we should attempt to update existing code where possible.

Boolean Operators

  • Boolean operators '&&' and '||' are prohibited, use the logical operators 'and' and 'or' instead.

...

Some existing control structures use boolean operators so code sniffer will warn about it. However, new files will be expected to follow this and we should attempt to update existing code where possible.

Code Documentation/Comments

  • Perl-style comments are not allowed
  • Files should not contain commented out code
  • Classes, Files and Functions
    • Must have phpdocs
    • Must use "/**" style comments
  • Files should start with the following Rogo boilerplate (unless 3rd party code)

...

Some existing classes, files and functions have no docs, use a bad style, do not have a boilerplate or contain commented out code so code sniffer will warn about it. However, new files will be expected to follow this and we should attempt to update existing code where possible.

Page Parameters

  • $_GET, $_POST and $_REQUEST super globals must not be accessed directly. Instead values passed to them should be access via param::required(), param::optional() or check_var()

    • If param::required() is used the code must handle the exception that will occur if it is not set.

    • check_var() will automatically display a message and terminate the script if a required parameter is not present

    • param::optional() allows a value other than null to be returned if it is not set, so is recommended over check_var() for parameters that are not required.

...

Some existing code uses direct access so code sniffer will warn about it. However, new files will be expected to follow this and we should attempt to update existing code where possible.

Auto-loading

  • In order to be autoloaded classes must:
    • use the file extenstion '.class.php'
    • be located in any of the following locations:
      • <base dir>/classes
      • <base dir>/*/classes
      • <base dir>/plugins/*/classes

...

Although it is good practice not to show PHP errors on a production server, Rogō should be written so that no errors occur when error reporting is set to E_ALL.

Things to Avoid

Globals

Where possible the use of global variables should be minimised. The $GLOBAL[] syntax should never be used.

...

It is expected that all new features and bug fixes come with behat tests. The caveat to this is if appropriate data generators or feature steps do not exist. It which case it would be appreciated if these can be created. If this is not possible due to time constraints please inform the code reviewers.

Behat testing


Javascript

See Javascript Modularisation

...

Javascript and css are minimised on the auto build environment. If you wish to build Rogo from source on your own development environment you will need to use Grunt to minify your js and css.


HTML

HTML should comply to the WCAG 2.1 standard at a minium.