-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
SessionInterface::getFlashBag() error reported by PHP Stan #39222
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
Comments
note: You can fix it by adding |
Isn't a redundancy checking if the injected interface is an instance of the only service that (by default) implements it and is defined in the DI mapping? |
Nobody promises that your class will be instantiated by the Symfony DI mapping. Of course, that is the case in the normal path (and it's very likely to always be the case), but the point of static analysis is exactly to avoid issues if this unexpected situation does occur. If you don't like that, I recommend tweaking your PHPstan configuration to no longer complain about this issue (or add PHPdocs to indicate that you trust that it's always a |
As write doc we can use |
Thanks, @grogy - funny thing no one mentioned it until now 😄 and I was not aware of this interface |
Symfony version(s) affected:
Both 4.x and 5.x
Description
Symfony cannot inject by default the
Session
service because it's not mapped as a service, so we need to inject theSessionInterface
. However,PHP Stan
reports an error when callinggetFlashBag()
How to reproduce
Inject the
SessionInterface
and then call thegetFlashBag()
method. Finally, runvendor/bin/phpstan analyse src -l 2
for alevel 2
analysis, where we should get that error message.Possible Solution
Define the
getFlashBag()
method into theSessionInterface
.Alternatively, maybe you can give another option to pass this error reported by PHP Stan without adding extra annotations to ignore these lines once after another when they are in use in several services.
The text was updated successfully, but these errors were encountered: