CodingStandards » History » Version 43
« Previous -
Version 43/64
(diff) -
Next » -
Current version
moyo, 02/26/2009 06:32 PM
One tabulation OR X spaces
{{{
// base level
// level 1
// level 2
// level 1
// base level
?>
}}}
STATE : accepted : 3 spaces
TODO : review all code
Remi: tabs is better than spaces, could be use with all indent values
MoYo: this is typically the problem. Tabs are not always displayed using the number of spaces. So, source code can be unreadble using several editors. Then using it dev use spaces instead of tabs and it make source code unhomogenous.
Control structuresMultiple conditions in several idented lines
{{{
if ($test1){
for ($i=0;$i<$end;$i++){
echo "test ".( $i<10 ? "0$i" : $i )."<br>";
}
}
if ($a==$b
| ($c==$d
&& $e==$f)){
}
switch ($test2){
case 1 :
echo "Case 1";
break;
case 2 :
echo "Case 2";
break;
default :
echo "Default Case";
break;
}
?>
}}}
STATE : accepted
TODO : review all code
Remi: space before ( and afer )
{{{
if ($toto) {
...
} else if {
...
} else {
...
}
}}}
Remi: sould comment if closing } more than xx line avay from opening { (p.e. 20 lines ~ 1 screen)
Remi: a comment in a switch case without break (not notice it's not a mistake)
include_once in order to include the file once and to raise warning if file does not exists
{{{
include_once(GLPI_ROOT."/inc/includes.php");
}}}
STATE : accepted
TODO : require_once , include, require -> include_once
PHP tagsShort tag not allowed. Use complet tags.
{{{
// code
?>
}}}
STATE : accepted
TODO : nothing
FunctionsFunction names should be written in camelBack, for example:
{{{
function userName(){
}
?>
}}}
STATE : accepted
TODO : check all functions
Remi: no space between function name and ( for declaration and call
MoYo: not logical comparing to conditionnal structure.
ClassClass names should be written in CamelCase, for example:
{{{
class ExampleAuthentification{
}
?>
}}}
STATE : accepted
TODO : check all classes
VariablesVariable names should be as descriptive and short as possible.
Normal variables should be written in lower case. In case of multiple words use the _ separator.
Global variables should be written in UPPER case. In case of multiple words use the _ separator.
Example:
{{{
$user = 'glpi';
$users = array('glpi', 'glpi2', 'glpi3');
$users_groups = array('glpi', 'glpi2', 'glpi3');
$CFG_GLPI=array();
?>
}}}
STATE : accepted
TODO :
globals : $cfg_glpi $db $phproot $HTMLRel $lang (glpi_trad) $cfg_glpi_plugins $dbocs $pdf_ (maybe not real global) $plugins_hooks -> DONE
+ check some global variables need to be passed as arguments
Variable typesVariable types for use in DocBlocks for Doxygen:
Type | Description | |||
mixed | A variable with undefined (or multiple) type. | |||
integer | Integer type variable (whole number). | |||
float | Float type (point number). | |||
boolean | Logical type (true or false). | |||
string | String type (any value in "" or ' '). | |||
array | Array type. | |||
object | Object type. | |||
ressource | Resource type (returned by for example mysql_connect()). |
Inserting comment in source code for doxygen.
Result : full doc for variables, functions, classes...
STATE : accepted
TODO : check all source code
quotes / double quotesIn which way can we use " or ' in glpi code :
by example :
{{{
echo "dqmkdqmsl"
}}}
or
{{{
echo 'kjlkj'
}}}
After reading bench about strings : http://www.estvideo.net/dew/index/page/phpbench
- Best choice seems to be simple quote.
ex : echo 'toto' not echo "toto"
- best is to concat vars and string.
ex : echo 'toto'.$test.' est vivant.'
- Best choice between echo and print is echo.
- Best choice to construct string before make echo, result : decrease number of use echo.
STATE : accepted
TODO : check all source code
FilesName in lower case.
Maximum line length : 100 characters
STATE : accepted
TODO : check all files
ConstantsCapital letter :
{{{
COMPUTER_TYPE
}}}
STATE : accepted
TODO : check all constants
MySQLQueries must be written onto several lines, one MySQL item by line.
All MySQL words in UPPER case.
All item based must be slash protected (table name, field name, condition).
{{{
SELECT *
FROM `glpi_computers`
WHERE id='32'
AND ( `glpi_computers`.`name` LIKE '%toto%'
OR `glpi_computers`.`name` LIKE '%tata%' )
ORDER BY `glpi_computers`.`date_mod` ASC
LIMIT 1
}}}
STATE : accepted
TODO : check all source code
Remi: all values from variable, even integer should be single quoted