Skip to content

Code Conventions Style Guide

Robert Spencer edited this page May 10, 2024 · 3 revisions

Code / Style Guide

API

The API is built with Slim version 2.0

Logging

We are using Monolog for logging. In Standard pages we have $logger var that can be used if the debug is enabled in the System Settings. In the Slim APIs you can use $this->Logger-> var.

UI Standards

  • We use the AdminLTE theme to generate a consistent UX for our users. Before you make any UI changes please review the AdminLTE documentation for the best way to leverage the theme's built in JavaScript and CSS.
  • AdminLTE contains many JavaScript Plugins (including JQuery and Bootstrap), so before adding any external components, please evaluate the plugins already in the project.

General Code Formatting

  • We use editorconfig to normalize code styling.
  • Not all code styles are supported for normalization within editorconfig, so please refer to the list below
  • All files use LF (Unix) line endings. CI Tests will fail for any PR containing CRLF or CR line endings.

Tabs and Indents

  • All tabs are represented as spaces
  • A single "tab" is expanded to 2 spaces

Alignment

A new line should follow the following clauses:

  • else
  • elseif
  • while
  • finally
  • catch

New lines should not follow class or scope definitions like "class", "public", or "private"

Braces

All open braces should be on the same line as the control statement:

  • Class definitions
  • Method declarations
  • if, else, elseif
  • for, foreach
  • while
  • do
  • switch
  • try, catch, finally

All close braces should be on their own line.

Spaces

A space should occur:

  • Inside the parentheses in the following statements:
    • if, elseif
    • for, foreach
    • while
    • catch
    • switch
  • Before and after the following elements:
    • Binary operators: < > ==
    • Ternary Operators: $b ? $a : $b
    • String Concatenation Operator: .
    • Key => Value Operator
    • Assignment Operator: $b = 5
  • After
    • Comma
    • Semicolon
    • Type-casts
    • Short PHP Tag
    • Before
    • Close PHP Tag

PHP Tags

  • We don't use PHP short tags
  • We do use <?= in place of <?php echo
Clone this wiki locally