|
1 | | -Coding standards |
2 | | -================ |
3 | | - |
4 | | -Indentation |
5 | | ------------ |
6 | | - |
7 | | -- 3 spaces |
8 | | -- Max line width: 100 |
9 | | - |
10 | | -.. code-block:: php |
11 | | -
|
12 | | - <?php |
13 | | - // base level |
14 | | - // level 1 |
15 | | - // level 2 |
16 | | - // level 1 |
17 | | - // base level |
18 | | -
|
19 | | -Spacing |
20 | | -------- |
21 | | - |
22 | | -We've adopted "french spacing" rules in the code. The rule is: |
23 | | - |
24 | | -* for *simple* punctuation (``,``, ``.``): use *one space after* the punctuation sign |
25 | | -* for *double* punctuation (``!``, ``?``, ``:``): use *one space after and one space before* the punctuation sign |
26 | | -* for *opening* punctuation (``(``, ``{``, ``[``): use *one space before* the punctuation sign |
27 | | -* for *closing* punctuation ( ``)``, ``}``, ``]``): use *one space after* the punctuation sign, excepted for line end, when followed by a semi-colon (``;``) |
28 | | - |
29 | | -Of course, this rules only aplies on the source code, not on the strings (translatable strings, comments, ...)! |
30 | | - |
31 | | -Control structures |
32 | | ------------------- |
33 | | - |
34 | | -Multiple conditions in several idented lines |
35 | | - |
36 | | -.. code-block:: php |
37 | | -
|
38 | | - <?php |
39 | | - if ($test1) { |
40 | | - for ($i=0 ; $i<$end ; $i++) { |
41 | | - echo "test ".( $i<10 ? "0$i" : $i )."<br>"; |
42 | | - } |
43 | | - } |
44 | | - |
45 | | - if ($a==$b |
46 | | - || ($c==$d && $e==$f)) { |
47 | | - ... |
48 | | - } else if { |
49 | | - ... |
50 | | - } |
51 | | - |
52 | | - switch ($test2) { |
53 | | - case 1 : |
54 | | - echo "Case 1"; |
55 | | - break; |
56 | | - |
57 | | - case 2 : |
58 | | - echo "Case 2"; |
59 | | - // No break here : because... |
60 | | - |
61 | | - default : |
62 | | - echo "Default Case"; |
63 | | - } |
| 1 | +PHP Coding standards |
| 2 | +==================== |
64 | 3 |
|
65 | 4 | Arrays |
66 | 5 | ------ |
67 | 6 |
|
68 | 7 | Arrays must be declared using the short notation syntax (``[]``), long notation (``array()``) is forbidden. |
69 | 8 |
|
70 | | -true, false and null |
71 | | --------------------- |
72 | | -
|
73 | | -``true``, ``false`` and ``null`` constants mut be lowercase. |
74 | | -
|
75 | 9 | Including files |
76 | 10 | --------------- |
77 | 11 |
|
@@ -203,28 +137,6 @@ Could also be written as (see the ``\``): |
203 | 137 | ... |
204 | 138 | } |
205 | 139 |
|
206 | | -Variables and Constants |
207 | | ------------------------ |
208 | | - |
209 | | -* Variable names must be as descriptive and as short as possible, stay clear and concise. |
210 | | -* In case of multiple words, use the ``_`` separator, |
211 | | -* Variables must be **lower case**, |
212 | | -* Global variables and constants must be **UPPER case**. |
213 | | - |
214 | | -.. code-block:: php |
215 | | -
|
216 | | - <?php |
217 | | - $user = 'glpi'; |
218 | | - // put elements in alphabetic order |
219 | | - $users = array('glpi', 'glpi2', 'glpi3'); |
220 | | - $users = array('glpi1' => 'valeur1', |
221 | | - 'nexglpi' => array('down' => '1', |
222 | | - 'up' => array('firstfield' => 'newvalue')), |
223 | | - 'glpi2' => 'valeur2'); |
224 | | - $users_groups = array('glpi', 'glpi2', 'glpi3'); |
225 | | - |
226 | | - $CFG_GLPI = array(); |
227 | | -
|
228 | 140 | Comments |
229 | 141 | -------- |
230 | 142 |
|
|
0 commit comments