Skip to content

Commit 173caf9

Browse files
committed
added a document about code conventions
1 parent a90092c commit 173caf9

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

contributing/code/conventions.rst

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Conventions
2+
===========
3+
4+
The :doc:`standards` document describes the coding standards for the Symfony2
5+
projects and the internal and third-party bundles. This document describes
6+
coding standards and conventions used in the core framework to make it more
7+
consistent and predictable. You can follow them in your own code, but you
8+
don't need to.
9+
10+
Method Names
11+
------------
12+
13+
When an object has a "main" many relation with related "things"
14+
(objects, parameters, ...), the method names are normalized:
15+
16+
* ``get()``
17+
* ``set()``
18+
* ``has()``
19+
* ``all()``
20+
* ``replace()``
21+
* ``remove()``
22+
* ``clear()``
23+
* ``isEmpty()``
24+
* ``add()``
25+
* ``register()``
26+
* ``count()``
27+
* ``keys()``
28+
29+
The usage of these methods are only allowed when it is clear that there
30+
is a main relation:
31+
32+
* a ``CookieJar`` has many ``Cookie``s;
33+
34+
* a Service ``Container`` has many services and many parameters (as services
35+
is the main relation, we use the naming convention for this relation);
36+
37+
* a Console ``Input`` has many arguments and many options. There is no "main"
38+
relation, and so the naming convention does not apply.
39+
40+
For many relations where the convention does not apply, the following methods
41+
must be used instead (where ``XXX`` is the name of the related thing):
42+
43+
============== =================
44+
Main Relation Other Relations
45+
============== =================
46+
``get()`` ``getXXX()``
47+
``set()`` ``setXXX()``
48+
``has()`` ``hasXXX()``
49+
``all()`` ``getXXXs()``
50+
``replace()`` ``setXXXs()``
51+
``remove()`` ``removeXXX()``
52+
``clear()`` ``clearXXX()``
53+
``isEmpty()`` ``isEmptyXXX()``
54+
``add()`` ``addXXX()``
55+
``register()`` ``registerXXX()``
56+
``count()`` ``countXXX()``
57+
``keys()`` n/a
58+
============== =================

contributing/code/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Contributing Code
77
bugs
88
patches
99
security
10-
standards
1110
tests
11+
standards
12+
conventions
1213
license

contributing/map.rst.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
* :doc:`Bugs </contributing/code/bugs>` |
44
* :doc:`Patches </contributing/code/patches>` |
55
* :doc:`Security </contributing/code/security>` |
6-
* :doc:`Coding Standards</contributing/code/standards>` |
76
* :doc:`Tests </contributing/code/tests>` |
7+
* :doc:`Coding Standards</contributing/code/standards>` |
8+
* :doc:`Code Conventions</contributing/code/conventions>` |
89
* :doc:`License </contributing/code/license>`
910

1011
* **Documentation**:

0 commit comments

Comments
 (0)