Skip to content

Commit f104e1a

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Mention and recommend to use PHP-CS-Fixer when contributing code Reworded the note about dump() availability per environment Fixed an example in the form testing article Improved the routing debug article
2 parents 0381e78 + 13a9b18 commit f104e1a

File tree

4 files changed

+44
-35
lines changed

4 files changed

+44
-35
lines changed

contributing/code/standards.rst

+32-15
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;
@@ -224,7 +238,7 @@ Service Naming Conventions
224238
* A group name uses the underscore notation.
225239

226240
Documentation
227-
-------------
241+
~~~~~~~~~~~~~
228242

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

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

238-
* The ``@package`` and ``@subpackage`` annotations are not used.
252+
* The ``@package`` and ``@subpackage`` annotations are not used;
253+
254+
* Inline the ``@inheritdoc`` tag.
239255

240256
License
241-
-------
257+
~~~~~~~
242258

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

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

form/unit_testing.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ The simplest ``TypeTestCase`` implementation looks like the following::
5454

5555
$form = $this->factory->create(TestedType::class);
5656

57-
$object = TestObject::fromArray($formData);
57+
$object = new TestObject();
58+
// ...populate $object properties with the data stored in $formData
5859

5960
// submit the data to the form directly
6061
$form->submit($formData);

routing/debug.rst

+6-14
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@ How to Visualize And Debug Routes
66

77
While adding and customizing routes, it's helpful to be able to visualize
88
and get detailed information about your routes. A great way to see every
9-
route in your application is via the ``debug:router`` console command. Execute
10-
the command by running the following from the root of your project.
9+
route in your application is via the ``debug:router`` console command, which
10+
lists *all* the configured routes in your application:
1111

1212
.. code-block:: terminal
1313
1414
$ php app/console debug:router
1515
16-
This command will print a helpful list of *all* the configured routes in
17-
your application:
18-
19-
.. code-block:: text
20-
2116
------------------ -------- -------- ------ ----------------------------------------------
2217
Name Method Scheme Host Path
2318
------------------ -------- -------- ------ ----------------------------------------------
@@ -30,21 +25,18 @@ your application:
3025
------------------ -------- -------- ------ ----------------------------------------------
3126
3227
You can also get very specific information on a single route by including
33-
the route name after the command:
28+
the route name as the command argument:
3429

3530
.. code-block:: terminal
3631
3732
$ php app/console debug:router article_show
3833
39-
Likewise, if you want to test whether a URL matches a given route, you can
40-
use the ``router:match`` console command:
34+
Likewise, if you want to test whether a URL matches a given route, use the
35+
``router:match`` command. This is useful to debug routing issues and find out
36+
which route is associated with the given URL:
4137

4238
.. code-block:: terminal
4339
4440
$ php app/console router:match /blog/my-latest-post
4541
46-
This command will print which route the URL matches.
47-
48-
.. code-block:: text
49-
5042
Route "blog_show" matches

templating/debug.rst

+4-5
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ The same mechanism can be used in Twig templates thanks to ``dump()`` function:
4646
</a>
4747
{% endfor %}
4848

49-
By design, the ``dump()`` function is only available if the ``kernel.debug``
50-
setting (in ``config.yml``) is ``true``, to avoid leaking sensitive information
51-
in production. In fact, trying to use the ``dump()`` function when ``kernel.debug``
52-
is ``false`` (for example in the ``prod`` environment) will result in an
53-
application error.
49+
By design, the ``dump()`` function is only available in the ``dev`` and ``test``
50+
environments, to avoid leaking sensitive information in production. In fact,
51+
trying to use the ``dump()`` function in the ``prod`` environment will result in
52+
a PHP error.

0 commit comments

Comments
 (0)