Coding standards

All files have to be UTF-8 encoded, never use any other encoding.

PHP

We're using the PSR-1/PSR-2 coding standards for phpMyFAQ. You can find the definition of these coding standards here:

  • PSR-1
  • PSR-2
  • Naming conventions: Until we switch to namespaces, all PHP classes have to be prefixed with PMF_, e.g. PMF_Configuration

HTML

  • We use the HTML5 doctype, which is easy to remember: <!DOCTYPE html>
  • Four spaces for indentation, never tabs
  • Double quotes only, never single quotes
  • Always use proper indentation
  • Use tags and elements appropriate for an HTML5 doctype (e.g., self-closing tags)
  • Paragraphs of text should always be placed in a <p> tag. Never use multiple <br/> tags.
  • Every form input that has text attached should utilize a <label> tag, especially radio or checkbox elements.
  • Always put quotes around attributes for readability.

CSS / LESS

  • Two spaces for indentation, never tabs
  • Multiple-line approach (one property and value per line)
  • Always a space after a property's colon (.e.g, display: block; and not display:block;)
  • End all lines with a semi-colon
  • For multiple, comma-separated selectors, place each selector on it's own line
  • Attribute selectors, like input[type="text"] should always wrap the attribute's value in double quotes, for consistency and safety (see this blog post on unquoted attribute values that can lead to XSS attacks).

JavaScript

  • Four spaces for indentation, never tabs
  • End all lines with a semi-colon