11Coding Standards
22================
33
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.
87
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 .
1110
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+ --------------------------------------------
1413
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:
1731
1832.. code-block :: html+php
1933
@@ -122,7 +136,7 @@ example containing most features described below:
122136 }
123137
124138Structure
125- ---------
139+ ~~~~~~~~~
126140
127141* Add a single space after each comma delimiter;
128142
@@ -181,7 +195,7 @@ Structure
181195* Do not use spaces around ``[ `` offset accessor and before ``] `` offset accessor.
182196
183197Naming Conventions
184- ------------------
198+ ~~~~~~~~~~~~~~~~~~
185199
186200* Use camelCase, not underscores, for variable, function and method
187201 names, arguments;
@@ -228,7 +242,7 @@ Service Naming Conventions
228242 to ``something.service_name ``).
229243
230244Documentation
231- -------------
245+ ~~~~~~~~~~~~~
232246
233247* Add PHPDoc blocks for all classes, methods, and functions (though you may
234248 be asked to remove PHPDoc that do not add value);
@@ -239,14 +253,17 @@ Documentation
239253
240254* Omit the ``@return `` tag if the method does not return anything;
241255
242- * The ``@package `` and ``@subpackage `` annotations are not used.
256+ * The ``@package `` and ``@subpackage `` annotations are not used;
257+
258+ * Inline the ``@inheritdoc `` tag.
243259
244260License
245- -------
261+ ~~~~~~~
246262
247263* Symfony is released under the MIT license, and the license block has to be
248264 present at the top of every PHP file, before the namespace.
249265
266+ .. _`PHP CS Fixer tool` : http://cs.sensiolabs.org/
250267.. _`PSR-0` : http://www.php-fig.org/psr/psr-0/
251268.. _`PSR-1` : http://www.php-fig.org/psr/psr-1/
252269.. _`PSR-2` : http://www.php-fig.org/psr/psr-2/
0 commit comments