Hotaru Docs

 [həʊdɒks]

Hotaru Coding Standards

Hotaru Coding Standards

Drupal and Wordpress both have a list of guidelines based on the PEAR Coding Standards.

Check them out: Drupal Coding Standards, Wordpress Coding Standards

Hotaru also has similar standards, loosely based on the PEAR ones. Please try to keep your code clean and consistent with the rest of Hotaru when writing plugins.

Naming conventions

All classes should use studlyCaps for methods and properties, i.e. no spaces, hyphens or underscores, and capitalize the first letter of all words except the first. Class names should start with a capital. E.g.

class ClassName 
{
    protected classProperty = '';
 
    public function getClassProperty()
    {
        return $this->classProperty;
    }
}

Exception: Methods in plugin classes should use studlyCaps except for those triggered by plugin hooks, e.g.

public function this_is_a_plugin_hook()
{
    ....
}
 
public function thisIsNotAPluginHook()
{
    ....
}

The reason for this is to help identify plugin hook methods in a plugin class from other functions.

Function comments

Ensure each function has a comment block, e.g.:

/**
 * Generate either default or friendly urls
 *
 * @param array $parameters - an array of pairs, e.g. 'page' => 'about' 
 * @param string $head - either 'index' or 'admin'
 * @return string
 */

Curly braces

Every conditional statement should have braces. For functions, put the opening brace on the next line, but not for control structures (if, while, foreach, etc.) unless helpful for readability, e.g.

function url($parameters = array(), $head = 'index')
{

Control structures

Put a space between if, while, foreach, etc. and the opening bracket. This keeps the code clean and distinguishes conditionals from function calls, e.g.

if ($head == 'index') {
    $url = baseurl . 'index.php?';
}

Constants

Capitalize all constants, e.g.

if (FRIENDLY_URLS == "false") {
    if ($head == 'index') {
        $url = BASEURL . 'index.php?';
    }
}

PHP in HTML

When using PHP in HTML, use semi-colons after every statement, e.g.

<a href="<?php echo BASEURL; ?>"><?php echo $lang["example_home"]; ?></a>

Guard clauses

Reduce indentation by "returning first", e.g. instead of this:

if ($h->isPage('search')) {
 
    $search_terms = $h->cage->get->getMixedString2('search');         
    $this->search($search_terms);
    return true;
 
} else {
    return false;
}

You return false first...

if (!$h->isPage('search')) {
    return false;
}
 
$search_terms = $h->cage->get->getMixedString2('search');
$this->search($search_terms);
return true;

Indentation

Please use tabbed indentation, not spaces.

Breathing space

Put two new lines between functions.

Getting StartedDesign and LayoutPlugin DevelopmentAdvanced TopicsFunction ReferenceTroubleshooting