UNDER RECONSTRUCTION
Coding Standards
Everyone has different & strongly-seated beliefs about coding style topics like indentation (tabs vs. spaces), and whether curly braces are on their own lines, etc. We ask simply that you try to make your code contributions look like the code around them. The actual coding standards that will be used are outlined below, your patch will be modified to adhere to this style.
Some of the text below is stolen directly from Agavi Coding Style Guide (thanks, David).
PHP
Case
Use CamelCase for class and interface names. studlyCaps are used for method names, e.g. setHttpHeader(), and for class variables.
For array key names, or parameters, use underscores, e.g.
$this->getParameter('foo_bar');
$array['some_key'] = $someValue;
All keywords are lowercase, without exception. Examples:
if($foo !== false) {
foreach($foo as $bar) {
echo $bar;
}
}
Also, please use null and false, not NULL and FALSE etc.
Global constants shouldn't be used. If you use Class Constants, they should, of course, be all uppercase, with words separated by an underscore:
class Foo
{
const SOME_NONSENSE_CONSTANT = 4;
}
Indents
Use Tabs, not Spaces, to indent blocks. The first level (i.e. the class declaration) is not indented). Setting your editor to two spaces per tab makes tabs easier to use and more visually appealing.
Definitions
Class, Interface, Method and Function definitions should have a curly brace on the next line:
class AgaviFoo
{
public function getBar()
{
return;
}
}
Also, please do not prefix internal methods with an underscore. It's 2006, we're using PHP5, and we have the private and public keywords for that ;)
Type Hints
Use them whereever possible. For Propel 1.3 and later (which requires PHP 5.1 as the minimum version), please also use array type hints and make use of the new ability to declare type-hinted variables as optional:
public function foo(array $foo = array(), PropelExample $bar = null);
Blocks
Curly braces go on the same line as the code construct they belong to:
if (true) {
someCodeHere();
} elseif ($bar) {
// more code
}
We encourage spaces between constructs and parentheses and you may also choose to use spaces within () to make code blocks more readable:
if ( ($expr && $expr2) || ($expr3 && $expr4) ) {
someCodeHere();
} elseif ($bar) {
// more code
}
Even it the block is just one line long, use curly braces:
This is preferred:
if ( $blah == $blahblah ) {
// ...
}
and not:
if ( $blah ) return $blah; // NOT OK!!!
PHPDoc
We like them. This should appear at the top of each file:
<?php /* * $Id$ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals * and is licensed under the LGPL. For more information please see * <http://propel.phpdb.org>. */
This should appear before each class (example for Propel):
/** * Propel's main resource pool and initialization & configuration class. * * This static class is used to handle Propel initialization and to maintain all of the * open database connections and instantiated database maps. * * @author Hans Lellelid <hans@xmpl.rg> * @version $Revision$ * @package propel */
and then something like this for each method in your class:
/**
* Get a configuration value.
*
* @param string The name of the configuration directive.
* @param array An array of parameters.
*
* @return mixed The value of the directive, or null if not set.
*
* @author David Zuelke <dz@bitxtender.com>
* @author Another Author <another_author@xmpl.org>
* @since 0.11.0
*/
Please respect the 11 character gap between an @ and the value:
/** * * @var FooBar * @deprecated :) */
