Skip to content

Type inference for ContainerInterface::getParameter() #975

Description

@mglaman

Problem

ContainerDynamicReturnTypeExtension handles get() and has() but not getParameter(). Calling $container->getParameter('app.root') currently returns mixed (or whatever the native PHPStan type is) instead of the known parameter type.

For example, app.root is defined as a string parameter in core.services.yml:

parameters:
  app.root: ''

But $container->getParameter('app.root') cannot be inferred as string.

Proposed solution

Build a parameter map from the parameters: sections of service YAMLs in DrupalAutoloader (currently only the services: section is processed), then add a getParameter branch to ContainerDynamicReturnTypeExtension that resolves known parameter names to their types.

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions