Skip to content
ginatrapani edited this page Sep 13, 2010 · 87 revisions

Welcome to the ThinkTank Code style guide. When submitting pull requests, please make sure that your changes conform to the styles below.

Styles loosely based upon Drupal’s coding standards, which are themselves loosely based on the PEAR coding standards.

This document is a work in progress. When in doubt, follow the same style as existing ThinkTank code.

All Code

Lines should have no trailing whitespace at their end.

All indentation should not use tabs; use 4 spaces instead.

Comments, class, and variable names should use US English spelling.

Require_once statements should use single quotes, no parentheses, ie, require_once 'init.php';

File-naming conventions

ThinkTank implements the Model-View-Controller design pattern. All new code should follow suit. Read more about ThinkTank’s MVC implementation here.

When organizing and naming new files, keep the following guidelines in mind.

Views

View filenames should match the names of the controllers they correspond with. For example, the public.tpl view goes with the public.php controller.

Separate folder names by a dot. For example, the /account/index.php controller’s view filename is account.index.tpl.

Included template filenames start with an underscore, like _header.tpl

Model

Each file should contain exactly one class or interface.

Prefix filenames with class. for classes, and interface. for interfaces. For example, the CrawlerPlugin interface file is named interface.CrawlerPlugin.php. The User class file is named class.User.php.

Variable and method naming convention

Variables: Use lowercase with underscores to name variables, i.e., $view_template, unless its a constant. For constants, use underscores with all uppercase, i.e., const KEY_SEPARATOR="|";

Methods: Use CamelCase to name methods, i.e., public function isUserInDB($user_id);

PHP: When in doubt, use PHP5 style code conventions

  • Class constructors should be public function __construct(). Use destructors:http://www.php.net/manual/en/language.oop5.decon.php when appropriate.
  • Explicitly declare visibility::http://www.php.net/manual/en/language.oop5.visibility.php (public, private, protected) for member variables and methods
  • Do NOT use PHP closing tags, as per Zend framework style guide
    For files that contain only PHP code, the closing tag (“?>”) is never permitted. It is not required by PHP, and omitting it´ prevents the accidental injection of trailing white space into the response.

Language Specifics

Clone this wiki locally