Skip to content

Commit 2313443

Browse files
tomasfejfarlookyman
authored andcommitted
Fix for Psr\Container\ContainerInterface type
1 parent 7ad5b2c commit 2313443

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

extension.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ services:
2828
-
2929
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Symfony\Component\DependencyInjection\ContainerInterface, %symfony.constant_hassers%)
3030
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
31+
-
32+
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Psr\Container\ContainerInterface, %symfony.constant_hassers%)
33+
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
3134
-
3235
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\Controller, %symfony.constant_hassers%)
3336
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
@@ -39,6 +42,9 @@ services:
3942
-
4043
factory: PHPStan\Type\Symfony\ServiceTypeSpecifyingExtension(Symfony\Component\DependencyInjection\ContainerInterface)
4144
tags: [phpstan.typeSpecifier.methodTypeSpecifyingExtension]
45+
-
46+
factory: PHPStan\Type\Symfony\ServiceTypeSpecifyingExtension(Psr\Container\ContainerInterface)
47+
tags: [phpstan.typeSpecifier.methodTypeSpecifyingExtension]
4248
-
4349
factory: PHPStan\Type\Symfony\ServiceTypeSpecifyingExtension(Symfony\Bundle\FrameworkBundle\Controller\Controller)
4450
tags: [phpstan.typeSpecifier.methodTypeSpecifyingExtension]

src/Rules/Symfony/ContainerInterfacePrivateServiceRule.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ public function processNode(Node $node, Scope $scope): array
6161
$isControllerType = (new ObjectType('Symfony\Bundle\FrameworkBundle\Controller\Controller'))->isSuperTypeOf($argType);
6262
$isAbstractControllerType = (new ObjectType('Symfony\Bundle\FrameworkBundle\Controller\AbstractController'))->isSuperTypeOf($argType);
6363
$isContainerType = (new ObjectType('Symfony\Component\DependencyInjection\ContainerInterface'))->isSuperTypeOf($argType);
64-
if (!$isControllerType->yes() && !$isAbstractControllerType->yes() && !$isContainerType->yes()) {
64+
$isPsrContainerType = (new ObjectType('Psr\Container\ContainerInterface'))->isSuperTypeOf($argType);
65+
if (
66+
!$isControllerType->yes()
67+
&& !$isAbstractControllerType->yes()
68+
&& !$isContainerType->yes()
69+
&& !$isPsrContainerType->yes()
70+
) {
6571
return [];
6672
}
6773

src/Rules/Symfony/ContainerInterfaceUnknownServiceRule.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ public function processNode(Node $node, Scope $scope): array
5858
$isControllerType = (new ObjectType('Symfony\Bundle\FrameworkBundle\Controller\Controller'))->isSuperTypeOf($argType);
5959
$isAbstractControllerType = (new ObjectType('Symfony\Bundle\FrameworkBundle\Controller\AbstractController'))->isSuperTypeOf($argType);
6060
$isContainerType = (new ObjectType('Symfony\Component\DependencyInjection\ContainerInterface'))->isSuperTypeOf($argType);
61-
if (!$isControllerType->yes() && !$isAbstractControllerType->yes() && !$isContainerType->yes()) {
61+
$isPsrContainerType = (new ObjectType('Psr\Container\ContainerInterface'))->isSuperTypeOf($argType);
62+
if (
63+
!$isControllerType->yes()
64+
&& !$isAbstractControllerType->yes()
65+
&& !$isContainerType->yes()
66+
&& !$isPsrContainerType->yes()
67+
) {
6268
return [];
6369
}
6470

0 commit comments

Comments
 (0)