@@ -2,8 +2,60 @@ Coding Standards
2
2
================
3
3
4
4
When contributing code to Symfony2, you must follow its coding standards. To
5
- make a long story short, here is the golden rule: *Imitate the existing
6
- Symfony2 code *.
5
+ make a long story short, here is the golden rule: **Imitate the existing
6
+ Symfony2 code **. Most open-source Bundles and libraries used by Symfony2 also
7
+ follow the same guidelines, and you should too.
8
+
9
+ Remember that the main advantage of standards is that every piece of code
10
+ looks and feels familiar, it's not about this or that being more readable.
11
+
12
+ Since a picture - or some code - is worth a thousand words, here's a short
13
+ example containing most features described below:
14
+
15
+ .. code-block :: php
16
+
17
+ <?php
18
+
19
+ /*
20
+ * This file is part of the Symfony package.
21
+ *
22
+ * (c) Fabien Potencier <fabien @symfony.com >
23
+ *
24
+ * For the full copyright and license information, please view the LICENSE
25
+ * file that was distributed with this source code.
26
+ */
27
+
28
+ namespace Acme;
29
+
30
+ class Foo
31
+ {
32
+ const SOME_CONST = 42;
33
+
34
+ private $foo;
35
+
36
+ /**
37
+ * @param string $dummy Some argument description
38
+ */
39
+ public function __construct($dummy)
40
+ {
41
+ $this->foo = $this->transform($dummy);
42
+ }
43
+
44
+ /**
45
+ * @param string $dummy Some argument description
46
+ * @return string|null Transformed input
47
+ */
48
+ private function transform($dummy)
49
+ {
50
+ if (true === $dummy) {
51
+ return;
52
+ } elseif ('string' === $dummy) {
53
+ $dummy = substr($dummy, 0, 5);
54
+ }
55
+
56
+ return $dummy;
57
+ }
58
+ }
7
59
8
60
Structure
9
61
---------
@@ -35,8 +87,8 @@ Structure
35
87
* Put braces on their own line for classes, methods, and functions
36
88
declaration;
37
89
38
- * Separate the conditional statement and the opening brace with a single
39
- space and no blank line;
90
+ * Separate the conditional statements (` if `, ` else `, ...) and the opening
91
+ brace with a single space and no blank line;
40
92
41
93
* Declare visibility explicitly for class, methods, and properties (usage of
42
94
`var ` is prohibited);
@@ -68,9 +120,18 @@ Naming Conventions
68
120
69
121
* Use alphanumeric characters and underscores for file names;
70
122
123
+ * Don't forget to look at the more verbose :doc: `conventions ` document for
124
+ more subjective naming considerations.
125
+
71
126
Documentation
72
127
-------------
73
128
74
129
* Add PHPDoc blocks for all classes, methods, and functions;
75
130
76
131
* The `@package ` and `@subpackage ` annotations are not used.
132
+
133
+ License
134
+ -------
135
+
136
+ * Symfony is released under the MIT license, and the license block has to be
137
+ present at the top of every PHP file, before the namespace.
0 commit comments