Skip to content

Commit b9efa28

Browse files
committed
[Contributing] Add more information on deprecations
1 parent a728c69 commit b9efa28

File tree

1 file changed

+72
-19
lines changed

1 file changed

+72
-19
lines changed

contributing/code/conventions.rst

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,45 @@ must be used instead (where ``XXX`` is the name of the related thing):
7979

8080
.. _contributing-code-conventions-deprecations:
8181

82-
Deprecations
83-
------------
82+
Deprecating code
83+
----------------
8484

8585
From time to time, some classes and/or methods are deprecated in the
8686
framework; that happens when a feature implementation cannot be changed
8787
because of backward compatibility issues, but we still want to propose a
8888
"better" alternative. In that case, the old implementation can simply be
8989
**deprecated**.
9090

91+
Deprecations must only be introduced on the next minor version of the impacted
92+
component (or bundle, bridge, contract).
93+
They can exceptionally be introduced on previous supported versions if they are critical.
94+
95+
A new class (or interface, trait) cannot be introduced as deprecated, or
96+
contains deprecated methods.
97+
9198
A feature is marked as deprecated by adding a ``@deprecated`` phpdoc to
9299
relevant classes, methods, properties, ...::
93100

94101
/**
95-
* @deprecated since vendor-name/package-name 2.8, to be removed in 3.0. Use XXX instead.
102+
* @deprecated since Symfony 2.8.
96103
*/
97104

98-
The deprecation message should indicate the version when the class/method was
99-
deprecated, the version when it will be removed, and whenever possible, how
100-
the feature was replaced.
105+
The deprecation message must indicate the version when the class was deprecated,
106+
and whenever possible, how the feature was replaced::
101107

102-
A PHP ``E_USER_DEPRECATED`` error must also be triggered to help people with
103-
the migration starting one or two minor versions before the version where the
104-
feature will be removed (depending on the criticality of the removal)::
108+
/**
109+
* @deprecated since Symfony 2.8, use Replacement instead.
110+
*/
105111

106-
@trigger_error('XXX() is deprecated since vendor-name/package-name 2.8 and will be removed in 3.0. Use XXX instead.', E_USER_DEPRECATED);
112+
When the replacement is in another namespace than the deprecated class, its FQCN must be used::
113+
114+
/**
115+
* @deprecated since Symfony 2.8, use A\B\Replacement instead.
116+
*/
117+
118+
A PHP ``E_USER_DEPRECATED`` error must also be triggered to help people with th migration::
119+
120+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 2.8, use "%s" instead.', Deprecated::class, Replacement::class), E_USER_DEPRECATED);
107121

108122
Without the `@-silencing operator`_, users would need to opt-out from deprecation
109123
notices. Silencing swaps this behavior and allows users to opt-in when they are
@@ -114,19 +128,58 @@ the Web Debug Toolbar or by the PHPUnit bridge).
114128

115129
When deprecating a whole class the ``trigger_error()`` call should be placed
116130
between the namespace and the use declarations, like in this example from
117-
`ArrayParserCache`_::
131+
`ServiceRouterLoader`_::
118132

119-
namespace Symfony\Component\ExpressionLanguage\ParserCache;
133+
namespace Symfony\Component\Routing\Loader\DependencyInjection;
120134

121-
@trigger_error('The '.__NAMESPACE__.'\ArrayParserCache class is deprecated since version 3.2 and will be removed in 4.0. Use the Symfony\Component\Cache\Adapter\ArrayAdapter class instead.', E_USER_DEPRECATED);
135+
use Symfony\Component\Routing\Loader\ContainerLoader;
122136

123-
use Symfony\Component\ExpressionLanguage\ParsedExpression;
137+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ServiceRouterLoader::class, ContainerLoader::class), E_USER_DEPRECATED);
124138

125139
/**
126-
* @author Adrien Brault <adrien.brault@gmail.com>
127-
*
128-
* @deprecated since Symfony 3.2, to be removed in 4.0. Use the Symfony\Component\Cache\Adapter\ArrayAdapter class instead.
140+
* @deprecated since Symfony 4.4, use Symfony\Component\Routing\Loader\ContainerLoader instead.
129141
*/
130-
class ArrayParserCache implements ParserCacheInterface
142+
class ServiceRouterLoader extends ObjectRouteLoader
143+
144+
.. _`ServiceRouterLoader`: https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Routing/Loader/DependencyInjection/ServiceRouterLoader.php
145+
146+
The deprecation must be added to the ``CHANGELOG.md`` file of the impacted component::
147+
148+
4.4.0
149+
-----
150+
151+
* Deprecated the `Deprecated` class, use `Replacement` instead.
152+
153+
It must also be added to the ``UPGRADE.md`` file of the targeted minor version
154+
(``UPGRADE-4.4.md`` in our example)::
155+
156+
DependencyInjection
157+
-------------------
158+
159+
* Deprecated the `Deprecated` class, use `Replacement` instead.
160+
161+
Finally, its consequences must be added to the ``UPGRADE.md`` file of the next major version
162+
(``UPGRADE-5.0.md`` in our example)::
163+
164+
DependencyInjection
165+
-------------------
166+
167+
* Removed the `Deprecated` class, use `Replacement` instead.
168+
169+
All these tasks are mandatory and must be done in the same pull request.
170+
171+
Removing deprecated code
172+
------------------------
173+
174+
Removing deprecated code can only be done once every 2 year, on the next major version of the
175+
impacted component (``master`` branch).
176+
177+
When removing deprecated code, the consequences of the deprecation must be added to the ``CHANGELOG.md`` file
178+
of the impacted component::
179+
180+
5.0.0
181+
-----
182+
183+
* Removed the `Deprecated` class, use `Replacement` instead.
131184

132-
.. _`ArrayParserCache`: https://github.com/symfony/symfony/blob/3.2/src/Symfony/Component/ExpressionLanguage/ParserCache/ArrayParserCache.php
185+
This task is mandatory and must be done in the same pull request.

0 commit comments

Comments
 (0)