Skip to content

Commit c6676e8

Browse files
committed
minor #12075 [Contributing] Add more information on deprecations (fancyweb)
This PR was merged into the 3.4 branch. Discussion ---------- [Contributing] Add more information on deprecations The goal is to add information I gathered from @nicolas-grekas and others in reviews about what the core team expect when you deprecate / remove code. I will add a section for "Features" later. Commits ------- 71560da [Contributing] Add more information on deprecations
2 parents 8dd5ebc + 71560da commit c6676e8

File tree

1 file changed

+74
-19
lines changed

1 file changed

+74
-19
lines changed

contributing/code/conventions.rst

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,47 @@ 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, or bridge, or contract).
93+
They can exceptionally be introduced on previous supported versions if they are critical.
94+
95+
A new class (or interface, or trait) cannot be introduced as deprecated, or
96+
contain deprecated methods.
97+
98+
A new method cannot be introduced as deprecated.
99+
91100
A feature is marked as deprecated by adding a ``@deprecated`` phpdoc to
92101
relevant classes, methods, properties, ...::
93102

94103
/**
95-
* @deprecated since vendor-name/package-name 2.8, to be removed in 3.0. Use XXX instead.
104+
* @deprecated since Symfony 2.8.
105+
*/
106+
107+
The deprecation message must indicate the version in which the feature was deprecated,
108+
and whenever possible, how it was replaced::
109+
110+
/**
111+
* @deprecated since Symfony 2.8, use Replacement instead.
96112
*/
97113

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.
114+
When the replacement is in another namespace than the deprecated class, its FQCN must be used::
115+
116+
/**
117+
* @deprecated since Symfony 2.8, use A\B\Replacement instead.
118+
*/
101119

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)::
120+
A PHP ``E_USER_DEPRECATED`` error must also be triggered to help people with the migration::
105121

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);
122+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 2.8, use "%s" instead.', Deprecated::class, Replacement::class), E_USER_DEPRECATED);
107123

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

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

119-
namespace Symfony\Component\ExpressionLanguage\ParserCache;
135+
namespace Symfony\Component\Routing\Loader\DependencyInjection;
120136

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);
137+
use Symfony\Component\Routing\Loader\ContainerLoader;
122138

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

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

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

0 commit comments

Comments
 (0)