Versions Compared

Key

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

...

  1. Function calls should be typed, including the return type.

PSR Coding Style

Registry PE generally adopts PSR-12, with some variations. Where discrepancies exist between this section and the rest of this document, this section controls and the conflict should be assumed to be a legacy artifact that has not been updated.

In general, CakePHP Coding Conventions should also be followed, except where they conflict with guidance in this document.

Variations

  1. Indent 2 spaces rather than 4. This is a change to PSR-12 §2.4. Indenting 4 spaces makes code sprawl horizontally, making it harder to read and more difficult to keep to 80 characters per line (PSR-12 §2.3).
  2. Empty lines should have white space aligned to the start of the preceding line. This makes it easier to visually align blocks of code without have the cursor jump all over the place. This is technically a change to PSR-12 §2.3.
  3. Ignore CakePHP guidance on Line Length. PSR-12 §2.3 controls (line length target of 80 characters, soft limit of 120 characters, no hard limit).
  4. Ignore CakePHP guidance on nested ternaries. Nested Ternary Operations are permitted with concise, and can be written more clearly than the equivalent if/then/if/then/else clause.

Differences From The COmanage Coding Style

For developers already familiar with the v4 and earlier coding style, this section highlights the changes:

  1. Method names MUST be declared in camelCase (PSR-1 §4.3). While this was already generally the case, there are some places that used under_score style names.
  2. Use short form of type keywords (PSR-12 §2.5). There was not previously a standard, so (eg) int and integer were used interchangeable.
  3. Opening braces for function definitions start on a new line (PSR-12 §4.4).
  4. Multi-line function arguments are each placed on their own line (PSR-12 §4.5).
  5. Spacing for if/then/else (PSR-12 §5.1), while (§5.3), for (§5.4), foreach (§5.5), and try/catch (§5.6). A space is now always inserted after a keyword, and alignment for expressions split across multiple lines has changed.

Automating PSR-12 Compliance

XXX PHP_CodeSniffer

Adding New Models

Data Model and Functional Design

...