-
Notifications
You must be signed in to change notification settings - Fork 0
Coding Standards
alganet edited this page Feb 3, 2012
·
1 revision
This is a work in progress. Things will change.
Loosely based on http://symfony.com/doc/2.0/contributing/code/standards.html and PEAR standards.
- Full <?php opening tags and no closing tag at all for class and standard PHP-only files.
- Echoing is allowed using <?= syntax.
- Indent by 4 spaces. Never use tabs.
- Single space after commas everywhere.
- No spaces after opening or before closing parenthesis.
- Single spaces around operators.
- Braces are forbidden for single-line statements. A line break after the one-line block is mandatory.
- Opening and closing braces for classes and methods are on a new line.
- Opening braces for control structures (if, while, etc) are on the same line, separated by a single space.
- PHP keywords are lowercase. (null, true, false, array, etc...)
- Constants are always uppercase with words separated by underscores.
- Follow the PSR-0 convention.
- Class structure follows this order:
- Constants alphabetically
- Static Properties alphabetically (public, protected, private).
- Properties alphabetically (public, protected, private).
- Abstract Methods alphabetically (public, protected, private).
- Static Methods alphabetically (public, protected, private).
- Methods alphabetically (public, protected, private).
- Name everything inside a class using camelCase.
- Name everything outside a class using underscore_separated.
- Avoid getters and setters.
- Use dockblocks only when needed.
- Getters and setters doesn't need dockblocks. Make them self-descriptive.
- Constructors and Destructors doesn't need dockblocks. Make its parameters self-descriptive.
- Private and protected methods doesn't need dockblocks. Make them descriptive or velociraptors will come for you.
- Type-hint everything you can.
- Untyped parameters must be considered "mixed" always and handle type casting if appropriate.
- Pass-only parameters must be preferable not altered.
- Use naming conventions for common operations:
- get() or getXXX()
- set() or setXXX()
- has() or hasXXX()
- all() or getXXXs()
- replace()
- remove() or removeXXX()
- clear() or clearXXX()
- isEmpty() or isEmptyXXX()
- add() or addXXX()
- register() or registerXXX()
- count() or countXXX()
- keys()