Skip to content

Commit 2834e4a

Browse files
Simplify
1 parent c8644e1 commit 2834e4a

7 files changed

+23
-108
lines changed

extension.neon

-6
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,3 @@ services:
361361
class: PHPStan\Symfony\SymfonyContainerResultCacheMetaExtension
362362
tags:
363363
- phpstan.resultCacheMetaExtension
364-
-
365-
class: PHPStan\Type\Symfony\Container\KernelBrowserGetContainerDynamicReturnTypeExtension
366-
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
367-
-
368-
class: PHPStan\Type\Symfony\Container\KernelTestCaseGetContainerDynamicReturnTypeExtension
369-
tags: [phpstan.broker.dynamicStaticMethodReturnTypeExtension]

src/Rules/Symfony/ContainerInterfacePrivateServiceRule.php

+23-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PHPStan\Symfony\ServiceMap;
1111
use PHPStan\TrinaryLogic;
1212
use PHPStan\Type\ObjectType;
13-
use PHPStan\Type\Symfony\Container\TestContainerType;
1413
use PHPStan\Type\Type;
1514
use function sprintf;
1615

@@ -44,17 +43,11 @@ public function processNode(Node $node, Scope $scope): array
4443

4544
$argType = $scope->getType($node->var);
4645

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);
5447
$isOldServiceSubscriber = (new ObjectType('Symfony\Component\DependencyInjection\ServiceSubscriberInterface'))->isSuperTypeOf($argType);
5548
$isServiceSubscriber = $this->isServiceSubscriber($argType, $scope);
5649
$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()) {
5851
return [];
5952
}
6053

@@ -98,4 +91,25 @@ private function isServiceSubscriber(Type $containerType, Scope $scope): Trinary
9891
return $isContainerServiceSubscriber->or($serviceSubscriberInterfaceType->isSuperTypeOf($containedClassType)->result);
9992
}
10093

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+
101115
}

src/Type/Symfony/Container/KernelBrowserGetContainerDynamicReturnTypeExtension.php

-29
This file was deleted.

src/Type/Symfony/Container/KernelTestCaseGetContainerDynamicReturnTypeExtension.php

-29
This file was deleted.

src/Type/Symfony/Container/TestContainerType.php

-21
This file was deleted.

tests/Rules/Symfony/ContainerInterfacePrivateServiceRuleTest.php

-7
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,4 @@ public function testGetPrivateServiceInTest(): void
8787
);
8888
}
8989

90-
public static function getAdditionalConfigFiles(): array
91-
{
92-
return [
93-
__DIR__ . '/container-extensions.neon',
94-
];
95-
}
96-
9790
}

tests/Rules/Symfony/container-extensions.neon

-7
This file was deleted.

0 commit comments

Comments
 (0)