Skip to content

Commit 15e4e2c

Browse files
committed
[DependencyInjection] remove ServiceSubscriberTrait deprecation layer
1 parent 3b4f265 commit 15e4e2c

File tree

2 files changed

+17
-76
lines changed

2 files changed

+17
-76
lines changed

Service/ServiceSubscriberTrait.php

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -37,61 +37,31 @@ public static function getSubscribedServices(): array
3737
}
3838

3939
$services = \is_callable(['parent', __FUNCTION__]) ? parent::getSubscribedServices() : [];
40-
$attributeOptIn = false;
4140

42-
if (\PHP_VERSION_ID >= 80000) {
43-
foreach ((new \ReflectionClass(self::class))->getMethods() as $method) {
44-
if (self::class !== $method->getDeclaringClass()->name) {
45-
continue;
46-
}
47-
48-
if (!$attribute = $method->getAttributes(SubscribedService::class)[0] ?? null) {
49-
continue;
50-
}
51-
52-
if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) {
53-
throw new \LogicException(sprintf('Cannot use "%s" on method "%s::%s()" (can only be used on non-static, non-abstract methods with no parameters).', SubscribedService::class, self::class, $method->name));
54-
}
55-
56-
if (!$returnType = $method->getReturnType()) {
57-
throw new \LogicException(sprintf('Cannot use "%s" on methods without a return type in "%s::%s()".', SubscribedService::class, $method->name, self::class));
58-
}
59-
60-
$serviceId = $returnType instanceof \ReflectionNamedType ? $returnType->getName() : (string) $returnType;
61-
62-
if ($returnType->allowsNull()) {
63-
$serviceId = '?'.$serviceId;
64-
}
65-
66-
$services[$attribute->newInstance()->key ?? self::class.'::'.$method->name] = $serviceId;
67-
$attributeOptIn = true;
41+
foreach ((new \ReflectionClass(self::class))->getMethods() as $method) {
42+
if (self::class !== $method->getDeclaringClass()->name) {
43+
continue;
6844
}
69-
}
70-
71-
if (!$attributeOptIn) {
72-
foreach ((new \ReflectionClass(self::class))->getMethods() as $method) {
73-
if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) {
74-
continue;
75-
}
7645

77-
if (self::class !== $method->getDeclaringClass()->name) {
78-
continue;
79-
}
46+
if (!$attribute = $method->getAttributes(SubscribedService::class)[0] ?? null) {
47+
continue;
48+
}
8049

81-
if (!$returnType = $method->getReturnType()) {
82-
continue;
83-
}
50+
if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) {
51+
throw new \LogicException(sprintf('Cannot use "%s" on method "%s::%s()" (can only be used on non-static, non-abstract methods with no parameters).', SubscribedService::class, self::class, $method->name));
52+
}
8453

85-
if ($returnType->isBuiltin()) {
86-
continue;
87-
}
54+
if (!$returnType = $method->getReturnType()) {
55+
throw new \LogicException(sprintf('Cannot use "%s" on methods without a return type in "%s::%s()".', SubscribedService::class, $method->name, self::class));
56+
}
8857

89-
if (\PHP_VERSION_ID >= 80000) {
90-
trigger_deprecation('symfony/service-contracts', '2.5', 'Using "%s" in "%s" without using the "%s" attribute on any method is deprecated.', ServiceSubscriberTrait::class, self::class, SubscribedService::class);
91-
}
58+
$serviceId = $returnType instanceof \ReflectionNamedType ? $returnType->getName() : (string) $returnType;
9259

93-
$services[self::class.'::'.$method->name] = '?'.($returnType instanceof \ReflectionNamedType ? $returnType->getName() : $returnType);
60+
if ($returnType->allowsNull()) {
61+
$serviceId = '?'.$serviceId;
9462
}
63+
64+
$services[$attribute->newInstance()->key ?? self::class.'::'.$method->name] = $serviceId;
9565
}
9666

9767
return $services;

Tests/Service/ServiceSubscriberTraitTest.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,6 @@
2222

2323
class ServiceSubscriberTraitTest extends TestCase
2424
{
25-
/**
26-
* @group legacy
27-
*/
28-
public function testLegacyMethodsOnParentsAndChildrenAreIgnoredInGetSubscribedServices()
29-
{
30-
$expected = [LegacyTestService::class.'::aService' => '?'.Service2::class];
31-
32-
$this->assertEquals($expected, LegacyChildTestService::getSubscribedServices());
33-
}
34-
35-
/**
36-
* @requires PHP 8
37-
*/
3825
public function testMethodsOnParentsAndChildrenAreIgnoredInGetSubscribedServices()
3926
{
4027
$expected = [
@@ -67,22 +54,6 @@ public function setContainer(ContainerInterface $container)
6754
}
6855
}
6956

70-
class LegacyTestService extends ParentTestService implements ServiceSubscriberInterface
71-
{
72-
use ServiceSubscriberTrait;
73-
74-
public function aService(): Service2
75-
{
76-
}
77-
}
78-
79-
class LegacyChildTestService extends LegacyTestService
80-
{
81-
public function aChildService(): Service3
82-
{
83-
}
84-
}
85-
8657
class TestService extends ParentTestService implements ServiceSubscriberInterface
8758
{
8859
use ServiceSubscriberTrait;

0 commit comments

Comments
 (0)