Skip to content

Session/SessionInterface inconsistency #323

Closed
@VincentLanglet

Description

@VincentLanglet

Hi @ondrejmirtes,

After the merge of 012305d
(cf #233)

The return type of Request::getSession is Session instead of SessionInterface.
This was not really true be could be considered as a good help for developers since

  • it was almost always true
  • there was no easy way to check for the getFlashBag method.
  1. This is not the case after the merge of symfony/symfony@c7b5802 in Symfony 6.2.
    Now, it's possible to do a $request->getSession() instanceof FlashBagAwareSessionInterface check.
    And, because of the stub, currently the stub is reported as always true which is not true...

  2. Currently, RequestStack::getSession is returning SessionInterface when Request::getSession() is returning Session.
    This should be fixed by reverting the stub for request, or adding a stub for RequestStack.

  3. The Request stub is loaded dynamically with the following extension https://github.com/phpstan/phpstan-symfony/blob/1.2.x/src/Symfony/InputBagStubFilesExtension.php#L19
    which means that

  • For user of SF <5.1, $request::getSession returns a SessionInterface.
  • For user of SF >=5.1, $request::getSession returns a Session.

Not sure this was expected

I'd like to improve the situation, what's your point of view about this ?
The easiest thing to do would be at least to introduce a stub for RequestStack, but there is maybe something better to do ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions