From 3eef45273583c3e524a94589350dd437d3a7acaf Mon Sep 17 00:00:00 2001 From: dron Date: Mon, 26 Apr 2021 17:48:55 +0300 Subject: [PATCH 1/2] Support for ServiceLocator --- src/Rules/Symfony/ContainerInterfacePrivateServiceRule.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Rules/Symfony/ContainerInterfacePrivateServiceRule.php b/src/Rules/Symfony/ContainerInterfacePrivateServiceRule.php index f97633c0..c471e6ba 100644 --- a/src/Rules/Symfony/ContainerInterfacePrivateServiceRule.php +++ b/src/Rules/Symfony/ContainerInterfacePrivateServiceRule.php @@ -54,7 +54,8 @@ public function processNode(Node $node, Scope $scope): array $isTestContainerType = (new ObjectType('Symfony\Bundle\FrameworkBundle\Test\TestContainer'))->isSuperTypeOf($argType); $isOldServiceSubscriber = (new ObjectType('Symfony\Component\DependencyInjection\ServiceSubscriberInterface'))->isSuperTypeOf($argType); $isServiceSubscriber = (new ObjectType('Symfony\Contracts\Service\ServiceSubscriberInterface'))->isSuperTypeOf($argType); - if ($isTestContainerType->yes() || $isOldServiceSubscriber->yes() || $isServiceSubscriber->yes()) { + $isServiceLocator = (new ObjectType('Symfony\Component\DependencyInjection\ServiceLocator'))->isSuperTypeOf($argType); + if ($isTestContainerType->yes() || $isOldServiceSubscriber->yes() || $isServiceSubscriber->yes() || $isServiceLocator->yes()) { return []; } From 16b334117a8642374dd894207264c340b7ca2724 Mon Sep 17 00:00:00 2001 From: dron Date: Tue, 27 Apr 2021 12:06:46 +0300 Subject: [PATCH 2/2] Support for ServiceLocator --- tests/Rules/Symfony/ExampleController.php | 5 +++++ tests/Rules/Symfony/container.xml | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/tests/Rules/Symfony/ExampleController.php b/tests/Rules/Symfony/ExampleController.php index 65d1359b..edbdaaf5 100644 --- a/tests/Rules/Symfony/ExampleController.php +++ b/tests/Rules/Symfony/ExampleController.php @@ -39,4 +39,9 @@ public function unknownGuardedServiceOutsideOfContext(): void $this->get('unknown'); } + public function privateServiceFromServiceLocator(): void + { + $this->get('service_locator')->get('private'); + } + } diff --git a/tests/Rules/Symfony/container.xml b/tests/Rules/Symfony/container.xml index f21aeae3..f3261e0a 100644 --- a/tests/Rules/Symfony/container.xml +++ b/tests/Rules/Symfony/container.xml @@ -3,5 +3,10 @@ + + + + +