Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Rules/Symfony/ContainerInterfaceUnknownServiceRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public function processNode(Node $node, Scope $scope): array
}

$argType = $scope->getType($node->var);
$isContainerBagType = (new ObjectType('Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface'))->isSuperTypeOf($argType);
if ($isContainerBagType->yes()) {
return [];
}

$isControllerType = (new ObjectType('Symfony\Bundle\FrameworkBundle\Controller\Controller'))->isSuperTypeOf($argType);
$isAbstractControllerType = (new ObjectType('Symfony\Bundle\FrameworkBundle\Controller\AbstractController'))->isSuperTypeOf($argType);
$isContainerType = (new ObjectType('Symfony\Component\DependencyInjection\ContainerInterface'))->isSuperTypeOf($argType);
Expand Down
14 changes: 14 additions & 0 deletions tests/Rules/Symfony/ContainerInterfaceUnknownServiceRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,18 @@ public function testGetPrivateServiceInAbstractController(): void
);
}

public function testGetPrivateServiceInLegacyServiceSubscriber(): void
{
if (!interface_exists('Symfony\Contracts\Service\ServiceSubscriberInterface')) {
self::markTestSkipped('The test needs Symfony\Contracts\Service\ServiceSubscriberInterface class.');
}

$this->analyse(
[
__DIR__ . '/ExampleServiceSubscriber.php',
],
[]
);
}

}
7 changes: 7 additions & 0 deletions tests/Rules/Symfony/ExampleServiceSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ public function privateService(): void
$this->get('private');
}

public function containerParameter(): void
{
/** @var \Symfony\Component\DependencyInjection\ParameterBag\ContainerBag $containerBag */
$containerBag = doFoo();
$containerBag->get('parameter_name');
}

/**
* @return string[]
*/
Expand Down