Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive with \Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface::get() #191

Closed
alexsakhnov opened this issue Aug 17, 2021 · 2 comments · Fixed by #192

Comments

@alexsakhnov
Copy link
Contributor

Symfony ContainerBagInterface implements Psr\Container\ContainerInterface but actually it returns a container parameter, not a service.

However ContainerInterfaceUnknownServiceRule checks for service existence, not parameter. For example this code

/** @var \Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface $params */
$parameterValue = $params->get('parameter_name');

results in the following error

Service "parameter_name" is not registered in the container.

I suggest to ignore subtypes of ContainerBagInterface in the ContainerInterfaceUnknownServiceRule. Is this correct?

@ondrejmirtes
Copy link
Member

Hi, this is easy to fix. See the instructions: https://phpstan.org/developing-extensions/type-system#querying-a-specific-type

Just adding an if with (new ObjectType(ContainerInterface::class))->isSuperTypeOf($argType)->yes() should be fine. There are already some exceptions there:

if (
!$isControllerType->yes()
&& !$isAbstractControllerType->yes()
&& !$isContainerType->yes()
&& !$isPsrContainerType->yes()
) {
return [];
}

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants