|
8 | 8 | use PHPStan\Rules\Rule; |
9 | 9 | use PHPStan\ShouldNotHappenException; |
10 | 10 | use PHPStan\Symfony\ServiceMap; |
| 11 | +use PHPStan\TrinaryLogic; |
11 | 12 | use PHPStan\Type\ObjectType; |
| 13 | +use PHPStan\Type\Type; |
12 | 14 | use function sprintf; |
13 | 15 |
|
14 | 16 | /** |
@@ -53,7 +55,7 @@ public function processNode(Node $node, Scope $scope): array |
53 | 55 |
|
54 | 56 | $isTestContainerType = (new ObjectType('Symfony\Bundle\FrameworkBundle\Test\TestContainer'))->isSuperTypeOf($argType); |
55 | 57 | $isOldServiceSubscriber = (new ObjectType('Symfony\Component\DependencyInjection\ServiceSubscriberInterface'))->isSuperTypeOf($argType); |
56 | | - $isServiceSubscriber = (newObjectType('Symfony\Contracts\Service\ServiceSubscriberInterface'))->isSuperTypeOf($argType); |
| 58 | + $isServiceSubscriber = $this->isServiceSubscriber($argType, $scope); |
57 | 59 | $isServiceLocator = (new ObjectType('Symfony\Component\DependencyInjection\ServiceLocator'))->isSuperTypeOf($argType); |
58 | 60 | if ($isTestContainerType->yes() || $isOldServiceSubscriber->yes() || $isServiceSubscriber->yes() || $isServiceLocator->yes()) { |
59 | 61 | return []; |
@@ -83,4 +85,12 @@ public function processNode(Node $node, Scope $scope): array |
83 | 85 | return []; |
84 | 86 | } |
85 | 87 |
|
| 88 | + private function isServiceSubscriber(Type $containerType, Scope $scope): TrinaryLogic |
| 89 | + { |
| 90 | + $serviceSubscriberInterfaceType = new ObjectType('Symfony\Contracts\Service\ServiceSubscriberInterface'); |
| 91 | + $containedClassType = new ObjectType($scope->getClassReflection()->getName()); |
| 92 | + return $serviceSubscriberInterfaceType->isSuperTypeOf($containerType) |
| 93 | + ->or($serviceSubscriberInterfaceType->isSuperTypeOf($containedClassType)); |
| 94 | + } |
| 95 | + |
86 | 96 | } |
0 commit comments