|
10 | 10 | use PHPStan\Symfony\ServiceMap;
|
11 | 11 | use PHPStan\TrinaryLogic;
|
12 | 12 | use PHPStan\Type\ObjectType;
|
13 |
| -use PHPStan\Type\Symfony\Container\TestContainerType; |
14 | 13 | use PHPStan\Type\Type;
|
15 | 14 | use function sprintf;
|
16 | 15 |
|
@@ -44,17 +43,11 @@ public function processNode(Node $node, Scope $scope): array
|
44 | 43 |
|
45 | 44 | $argType = $scope->getType($node->var);
|
46 | 45 |
|
47 |
| - if ( |
48 |
| - $argType instanceof TestContainerType |
49 |
| - || (new ObjectType('Symfony\Bundle\FrameworkBundle\Test\TestContainer'))->isSuperTypeOf($argType)->yes() |
50 |
| - ) { |
51 |
| - return []; |
52 |
| - } |
53 |
| - |
| 46 | + $isTestContainer = $this->isTestContainer($argType, $scope); |
54 | 47 | $isOldServiceSubscriber = (new ObjectType('Symfony\Component\DependencyInjection\ServiceSubscriberInterface'))->isSuperTypeOf($argType);
|
55 | 48 | $isServiceSubscriber = $this->isServiceSubscriber($argType, $scope);
|
56 | 49 | $isServiceLocator = (new ObjectType('Symfony\Component\DependencyInjection\ServiceLocator'))->isSuperTypeOf($argType);
|
57 |
| - if ($isOldServiceSubscriber->yes() || $isServiceSubscriber->yes() || $isServiceLocator->yes()) { |
| 50 | + if ($isTestContainer->yes() || $isOldServiceSubscriber->yes() || $isServiceSubscriber->yes() || $isServiceLocator->yes()) { |
58 | 51 | return [];
|
59 | 52 | }
|
60 | 53 |
|
@@ -98,4 +91,25 @@ private function isServiceSubscriber(Type $containerType, Scope $scope): Trinary
|
98 | 91 | return $isContainerServiceSubscriber->or($serviceSubscriberInterfaceType->isSuperTypeOf($containedClassType)->result);
|
99 | 92 | }
|
100 | 93 |
|
| 94 | + private function isTestContainer(Type $containerType, Scope $scope): TrinaryLogic |
| 95 | + { |
| 96 | + $testContainer = new ObjectType('Symfony\Bundle\FrameworkBundle\Test\TestContainer'); |
| 97 | + $isTestContainer = $testContainer->isSuperTypeOf($containerType)->result; |
| 98 | + |
| 99 | + $classReflection = $scope->getClassReflection(); |
| 100 | + if ($classReflection === null) { |
| 101 | + return $isTestContainer; |
| 102 | + } |
| 103 | + |
| 104 | + $containerInterface = new ObjectType('Symfony\Component\DependencyInjection\ContainerInterface'); |
| 105 | + $kernelTestCase = new ObjectType('Symfony\Bundle\FrameworkBundle\Test\KernelTestCase'); |
| 106 | + $containedClassType = new ObjectType($classReflection->getName()); |
| 107 | + |
| 108 | + return $isTestContainer->or( |
| 109 | + $containerInterface->isSuperTypeOf($containerType)->result->and( |
| 110 | + $kernelTestCase->isSuperTypeOf($containedClassType)->result, |
| 111 | + ), |
| 112 | + ); |
| 113 | + } |
| 114 | + |
101 | 115 | }
|
0 commit comments