1
1
Coding Standards
2
2
================
3
3
4
- When contributing code to Symfony, you must follow its coding standards. To
5
- make a long story short, here is the golden rule: **Imitate the existing
6
- Symfony code **. Most open-source Bundles and libraries used by Symfony also
7
- follow the same guidelines, and you should too.
4
+ Symfony code is contributed by thousands of developers around the world. To make
5
+ every piece of code look and feel familiar, Symfony defines some coding standards
6
+ that all contributions must follow.
8
7
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 .
8
+ These Symfony coding standards are based on the ` PSR-1 `_, ` PSR-2 `_ and ` PSR-4 `_
9
+ standards, so you may already know most of them .
11
10
12
- Symfony follows the standards defined in the ` PSR-0 `_, ` PSR-1 `_, ` PSR-2 `_ and ` PSR-4 `_
13
- documents.
11
+ Making your Code Follow the Coding Standards
12
+ --------------------------------------------
14
13
15
- Since a picture - or some code - is worth a thousand words, here's a short
16
- example containing most features described below:
14
+ Instead of reviewing your code manually, Symfony makes it simple to ensure that
15
+ your contributed code matches the expected code syntax. First, install the
16
+ `PHP CS Fixer tool `_ and then, run this command to fix any problem:
17
+
18
+ .. code-block :: terminal
19
+
20
+ $ cd your-project/
21
+ $ php php-cs-fixer.phar fix -v
22
+
23
+ If you forget to run this command and make a pull request with any syntax issue,
24
+ our automated tools will warn you about that and will provide the solution.
25
+
26
+ Symfony Coding Standards in Detail
27
+ ----------------------------------
28
+
29
+ If you want to learn about the Symfony coding standards in detail, here's a
30
+ short example containing most features described below:
17
31
18
32
.. code-block :: html+php
19
33
@@ -122,7 +136,7 @@ example containing most features described below:
122
136
}
123
137
124
138
Structure
125
- ---------
139
+ ~~~~~~~~~
126
140
127
141
* Add a single space after each comma delimiter;
128
142
@@ -181,7 +195,7 @@ Structure
181
195
* Do not use spaces around ``[ `` offset accessor and before ``] `` offset accessor.
182
196
183
197
Naming Conventions
184
- ------------------
198
+ ~~~~~~~~~~~~~~~~~~
185
199
186
200
* Use camelCase, not underscores, for variable, function and method
187
201
names, arguments;
@@ -224,7 +238,7 @@ Service Naming Conventions
224
238
* A group name uses the underscore notation.
225
239
226
240
Documentation
227
- -------------
241
+ ~~~~~~~~~~~~~
228
242
229
243
* Add PHPDoc blocks for all classes, methods, and functions (though you may
230
244
be asked to remove PHPDoc that do not add value);
@@ -235,14 +249,17 @@ Documentation
235
249
236
250
* Omit the ``@return `` tag if the method does not return anything;
237
251
238
- * The ``@package `` and ``@subpackage `` annotations are not used.
252
+ * The ``@package `` and ``@subpackage `` annotations are not used;
253
+
254
+ * Inline the ``@inheritdoc `` tag.
239
255
240
256
License
241
- -------
257
+ ~~~~~~~
242
258
243
259
* Symfony is released under the MIT license, and the license block has to be
244
260
present at the top of every PHP file, before the namespace.
245
261
262
+ .. _`PHP CS Fixer tool` : http://cs.sensiolabs.org/
246
263
.. _`PSR-0` : http://www.php-fig.org/psr/psr-0/
247
264
.. _`PSR-1` : http://www.php-fig.org/psr/psr-1/
248
265
.. _`PSR-2` : http://www.php-fig.org/psr/psr-2/
0 commit comments