Skip to content

Commit 8bee654

Browse files
committed
Mention and recommend to use PHP-CS-Fixer when contributing code
1 parent 25224cc commit 8bee654

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

contributing/code/standards.rst

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
Coding 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

124138
Structure
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

183197
Naming Conventions
184-
------------------
198+
~~~~~~~~~~~~~~~~~~
185199

186200
* Use camelCase, not underscores, for variable, function and method
187201
names, arguments;
@@ -223,7 +237,7 @@ Service Naming Conventions
223237
* A group name uses the underscore notation.
224238

225239
Documentation
226-
-------------
240+
~~~~~~~~~~~~~
227241

228242
* Add PHPDoc blocks for all classes, methods, and functions (though you may
229243
be asked to remove PHPDoc that do not add value);
@@ -234,14 +248,17 @@ Documentation
234248

235249
* Omit the ``@return`` tag if the method does not return anything;
236250

237-
* The ``@package`` and ``@subpackage`` annotations are not used.
251+
* The ``@package`` and ``@subpackage`` annotations are not used;
252+
253+
* Inline the ``@inheritdoc`` tag.
238254

239255
License
240-
-------
256+
~~~~~~~
241257

242258
* Symfony is released under the MIT license, and the license block has to be
243259
present at the top of every PHP file, before the namespace.
244260

261+
.. _`PHP CS Fixer tool`: http://cs.sensiolabs.org/
245262
.. _`PSR-0`: http://www.php-fig.org/psr/psr-0/
246263
.. _`PSR-1`: http://www.php-fig.org/psr/psr-1/
247264
.. _`PSR-2`: http://www.php-fig.org/psr/psr-2/

0 commit comments

Comments
 (0)