Skip to content

Commit 7d91629

Browse files
committed
Split global and PHP coding standards
1 parent 2451b85 commit 7d91629

File tree

6 files changed

+105
-93
lines changed

6 files changed

+105
-93
lines changed

source/checklists/reviewprocess.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Here is the process you must follow when you are reviewing a PR.
1010

1111
2. Check if unit tests are not failing,
1212
3. Check if coding standards checks are not failing,
13-
4. Review the code itself. It must follow :doc:`GLPI's coding standards <../codingstandards>`,
13+
4. Review the code itself. It must follow :doc:`GLPI's coding standards <../coding_standards/index>`,
1414
5. Using the Github review process, approve, request changes or just comment the PR,
1515

1616
* If some new methods are added, or if the request made important changes in the code, you should ask the developer to write some more unit tests

source/coding_standards/global.rst

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
Global 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+
}
64+
65+
true, false and null
66+
--------------------
67+
68+
``true``, ``false`` and ``null`` constants mut be lowercase.
69+
70+
Variables and Constants
71+
-----------------------
72+
73+
* Variable names must be as descriptive and as short as possible, stay clear and concise.
74+
* In case of multiple words, use the ``_`` separator,
75+
* Variables must be **lower case**,
76+
* Global PHP variables and constants must be **UPPER case**.
77+
78+
.. code-block:: php
79+
80+
<?php
81+
$user = 'glpi';
82+
// put elements in alphabetic order
83+
$users = ['glpi', 'glpi2', 'glpi3'];
84+
$users = ['glpi1' => 'valeur1',
85+
'nexglpi' => ['down' => '1',
86+
'up' => ['firstfield' => 'newvalue']],
87+
'glpi2' => 'valeur2'];
88+
$users_groups = ['glpi', 'glpi2', 'glpi3'];
89+
90+
$CFG_GLPI = [];

source/coding_standards/index.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Coding standards
2+
================
3+
4+
GLPI has a general set of coding standards and then additional requirements for specific languages/file types (PHP, JavaScript, Twig, etc).
5+
6+
.. toctree::
7+
:maxdepth: 2
8+
9+
global.rst
10+
php.rst

source/codingstandards.rst renamed to source/coding_standards/php.rst

Lines changed: 2 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,11 @@
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+
====================
643

654
Arrays
665
------
676

687
Arrays must be declared using the short notation syntax (``[]``), long notation (``array()``) is forbidden.
698

70-
true, false and null
71-
--------------------
72-
73-
``true``, ``false`` and ``null`` constants mut be lowercase.
74-
759
Including files
7610
---------------
7711

@@ -203,28 +137,6 @@ Could also be written as (see the ``\``):
203137
...
204138
}
205139
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-
228140
Comments
229141
--------
230142

source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ GLPI Developer Documentation
1414
:maxdepth: 2
1515

1616
sourcecode
17-
codingstandards
17+
coding_standards/index
1818
devapi/index
1919
checklists/index
2020
plugins/index

source/plugins/requirements.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ For instance, a plugin need both an install and an uninstall hook calls. Here is
237237
Coding standards
238238
^^^^^^^^^^^^^^^^
239239

240-
You must respect GLPI's :doc:`global coding standards <../codingstandards>`.
240+
You must respect GLPI's :doc:`global coding standards <../coding_standards/index>`.
241241

242242
In order to check for coding standards compliance, you can add the `glpi-project/coding-standard` to your composer file, using:
243243

0 commit comments

Comments
 (0)