All rules and guidelines in this document apply to PHP files unless otherwise noted. References to PHP/HTML files can be interpreted as files that primarily contain HTML, but use PHP for templating purposes.
The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
This section describes the format and naming convention of PHP only files.
- Name MUST be CamelCase
- e.g.
AdoptionRequest.php
- e.g.
- Name MUST be class name + type of class
- e.g.
AdoptionsController.php
- e.g.
- Letters MUST be all lowercase
- e.g.
home.php
- e.g.
- Words MUST be separated with a hyphen
- e.g.
sign_up_organization.php
- e.g.
This section describes the use of PHP tags in PHP and PHP/HTML files.
- Open tag MUST be on its own line and MUST be followed by a blank line
- i.e.
<?php
↵
↵
...
- i.e.
- Close tag MUST NOT be used in PHP files
- i.e. no
?>
- i.e. no
- Open/close tag MUST be on one line in PHP/HTML files
- i.e.
<?php ... ?>
- i.e.
- Short open tag MUST NOT be used
- i.e.
<?
→<?php
- i.e.
- Short echo tag SHOULD be used in PHP/HTML files
- i.e.
<?php echo
→<?=
- i.e.
This section describes the format for including and requiring files.
- Include/require once SHOULD be used
- i.e.
include
→include_once
,require
→require_once
- i.e.
- Parenthesis MUST NOT be used
- e.g.
include_once('file.php');
→include_once 'file.php';
- e.g.
- Purpose of include MUST be documented with a comment
- e.g.
// Provides helper functions
↵
require_once 'wp-load.php';
- e.g.
- Class MUST be in the Class Diagram
- Scope MUST be the Entity (not controller functionality)
- Keywords MUST be all uppercase
- Prepared Statements MUST be used
- Static Methods MAY be used
- Method Name SHOULD be meaningful and relevant.
- Columns MUST be defined in the query
- MUST return lastInsertId when available
- SHOULD not insert to auto_increment columns.
- Single Selects MUST return just one the object when selecting a single item (not a array of one object)
- Empty Parameters SHOULD be taken into consideration
- Repeated Logic MAY be refactored into functions
- Database Access MUST NOT be done. only the data passed by the controller SHOULD be used.
- Parameters MUST be validated for existence & validity
- Reasonable Defaults MAY be used for empty parameters.
- Formatter MUST be "bmewburn.vscode-intelephense-client" vs code extension.
- ALL FILES MUST be formatted before committing
Inspired in part by style guides from:
CodeIgniter, Drupal, Horde, Pear, PSR-1, PSR-2, Symfony, and WordPress.