Skip to content

[HttpFoundation] inconsistent argument annotation for method $request->query->get() #37882

Closed
@angelbachev

Description

@angelbachev

Symfony version(s) affected: 5.1.*

Description
In version 5.1.* the type of $query property in Request class was changed from ParameterBag to InputBag.
InputBag extends ParameterBag but modified method get() signature.
This make the following code (which works fine in 5.0.*) invalid
$languages = $request->query->get('languages', ['en']);
In the project I'm currently working on we use PHPStan which is part of our continuous integration process.
PHPStan throws a lot of warnings because of this inconsistency.

How to reproduce
Run a PHPStan on a file which call $request->query->get() with array as default argument.

Possible Solution
Change Request::query type back to ParameterBag

Additional context
In Symfony 5.0.*
image

In Symfony 5.1.*
image

PHPStan error:
Parameter #2 $default of method Symfony\Component\HttpFoundation\InputBag::get() expects string|null, array<int, string> given.

According to the official Symfony 5.1.* documentation the type of query is ParameterBag, not InputBag.
https://symfony.com/doc/current/components/http_foundation.html#accessing-request-data
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions