.. _coding-style-label: Coding Style ============ Scope of style guidelines ------------------------- In order to keep the code consistent, please use the following conventions. These conventions are no judgement call on your coding abilities, but more of a style and look call. Performance and Readability --------------------------- * It is more important to be correct than to be fast. * It is more important to be maintainable than to be fast. * Fast code that is difficult to maintain is likely going to be looked down upon. Indentation and line length --------------------------- - 2 spaces - Max line width: 80 .. code-block:: php foo(bar() + 4)) { } For vars declaration place values on the same column .. code-block:: php 6 && $b == 17 && (foo($b) < 1)) { } Braces ------ If statements with or without else clauses are formatted like this: .. code-block:: php Including files --------------- Use ``require_once`` in order to include the file once and to raise warning if file does not exists: .. code-block:: php with double quotes, $a will be "Hello bar" if $foo = 'bar' // => with single quotes, $a will be "Hello $foo" $a = "Hello $foo"; //use single quotes for array keys $tab = array( 'lastname' => 'john', 'firstname' => 'doe' ); //Do not use concatenation to optimize PHP7 //note that you cannot use functions call in {} $a = "Hello {$tab['firstname']}"; //single quote translations $str = _('My string to translate'); //Double quote for special characters $html = "
One paragraph
\nAnother one
"; //single quote cases switch ($a) { case 'foo' : //use single quote here ... case 'bar' : ... } Files Format ------------ * UTF-8, LF - not CR LF .. _checking-standard-label: Checking standards ------------------ In order to check some standards are respected, we provide some custom `PHP CodeSniffer