-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] deprecate the @required
annotation
#48990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DependencyInjection] deprecate the @required
annotation
#48990
Conversation
fbad3f3
to
43c1d66
Compare
src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredMethodsPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredMethodsPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredPropertiesPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredPropertiesPass.php
Outdated
Show resolved
Hide resolved
43c1d66
to
dcf42d3
Compare
@required
annotation
src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredMethodsPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredPropertiesPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowireRequiredMethodsPassTest.php
Outdated
Show resolved
Hide resolved
Thanks for the reviews! Suggestions have been proceeded. |
src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredMethodsPass.php
Outdated
Show resolved
Hide resolved
70b6c7d
to
7c0b7ba
Compare
I tried to improve the deprecation by showing the source of the deprecation, and fixed a bug that reported a deprecation when using Hopefully I fixed the tests, I duplicated some of them, in order to test |
9cb1ec0
to
65100a3
Compare
src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredPropertiesPass.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more. 8000
The @group legacy
annotation should be added only on test cases that should be removed on v7. I don't think that's the case right now.
Instead of adding it to many test cases, we should update them to use the attribute, and ensure we keep at least one test ensuring that the annotation still works.
src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredPropertiesPass.php
Outdated
Show resolved
Hide resolved
65100a3
to
55e55dc
Compare
495e11b
to
ab4386c
Compare
I didn't know how to decide if only one test with But please let me know if some cases can be dropped. |
e1191b1
to
85b4f9e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second look, this misses at least the following patch. It's not enought because then you'll see
4x: Since symfony/dependency-injection 6.3: The "@required" annotation on methods is deprecated, use the "Symfony\Contracts\Service\Attribute\Required" attribute instead.
2x in AutowirePassTest::testExplicitMethodInjectionAttribute from Symfony\Component\DependencyInjection\Tests\Compiler
2x in AutowireRequiredMethodsPassTest::testExplicitMethodInjectionAttribute from Symfony\Component\DependencyInjection\Tests\Compiler
But this is legit: testExplicitMethodInjectionAttribute is currently using SetterInjection::class
, which is itself deprecated. The test needs to be updated to not use any deprecated class.
diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredMethodsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredMethodsPass.php
index 53ae32af85..bf1954a00e 100644
--- a/src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredMethodsPass.php
+++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredMethodsPass.php
@@ -69,6 +69,7 @@ class AutowireRequiredMethodsPass extends AbstractRecursivePass
if (false === stripos($doc, '@inheritdoc') || !preg_match('#(?:^/\*\*|\n\s*+\*)\s*+(?:\{@inheritdoc\}|@inheritdoc)(?:\s|\*/$)#i', $doc)) {
break;
}
+ trigger_deprecation('symfony/dependency-injection', '6.3', 'The "@required" annotation on methods is deprecated, use the "Symfony\Contracts\Service\Attribute\Required" attribute instead.');
}
try {
$r = $r->getPrototype();
diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php
index 42ce6c6ee1..34ff97ce1e 100644
--- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php
+++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php
@@ -947,13 +947,9 @@ class AutowirePassTest extends TestCase
/**
* @dataProvider provideNotWireableCalls
- *
- * @group legacy
*/
public function testNotWireableCalls($method, $expectedMsg)
{
- $this->expectDeprecation('Since symfony/dependency-injection 6.3: The "@required" annotation on methods is deprecated, use the "Symfony\Contracts\Service\Attribute\Required" attribute instead.');
-
$container = new ContainerBuilder();
$foo = $container->register('foo', NotWireable::class)->setAutowired(true)
@@ -986,13 +982,8 @@ class AutowirePassTest extends TestCase
];
}
- /**
- * @group legacy
- */
public function testSuggestRegisteredServicesWithSimilarCase()
{
- $this->expectDeprecation('Since symfony/dependency-injection 6.3: The "@required" annotation on methods is deprecated, use the "Symfony\Contracts\Service\Attribute\Required" attribute instead.');
-
$container = new ContainerBuilder();
$container->register(LesTilleuls::class, LesTilleuls::class);
diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes.php
index 3083be42c2..4a2c1f457f 100644
--- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes.php
+++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes.php
@@ -446,8 +446,7 @@ class NotWireable
{
}
- // @deprecated since Symfony 6.3, to be removed in 7.0
- /** @required */
+ #[Required]
protected function setProtectedMethod(A $a)
{
}
@nicolas-grekas thanks for the detailed report! I applied these suggestions. In the first code block of your last comment (in |
e3bca72
to
bcc0e19
Compare
src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php
Outdated
Show resolved
Hide resolved
@@ -67,6 +69,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed | |||
if (false === stripos($doc, '@inheritdoc') || !preg_match('#(?:^/\*\*|\n\s*+\*)\s*+(?:\{@inheritdoc\}|@inheritdoc)(?:\s|\*/$)#i', $doc)) { | |||
break; | |||
} | |||
trigger_deprecation('symfony/dependency-injection', '6.3', 'The "@required" annotation on methods is deprecated, use the "Symfony\Contracts\Service\Attribute\Required" attribute instead.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one looks wrong to me. It will trigger the deprecation for any method using @inheritdoc
, which is totally wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same question: #48990 (comment)
src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredMethodsPass.php
Outdated
Show resolved
Hide resolved
5f25ae8
to
06ad958
Compare
Status: Needs Review |
06ad958
to
9d69e4b
Compare
Thank you @alexislefebvre. |
…red`` (alexislefebvre) This PR was merged into the 6.3 branch. Discussion ---------- Update the upgrade guide for the deprecation of ``@required`` | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | . | License | MIT | Doc PR | . Follow-up of #48990 Commits ------- 092d889 UPGRADE-6.3.md: deprecate "`@required`"
TODO:
symfony/framework-bundle
(that calladdGlobalIgnoredName('required')
)?symfony/dependency-injection
(that detect and is called when there is this annotation)?$this->expectDeprecation
doesn't work as I expected