-
Notifications
You must be signed in to change notification settings - Fork 88
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
any way to support typing for $request->request->get()? #262
Comments
Can you be more specific with a code sample and the error you're getting? |
I see there is |
Still not sure what this is about. I'll reopen if you clarify, thanks. |
PHPSTAN ERROR: |
hopefully the above clarifies @ondrejmirtes |
Can you please post these? Put them in the source code and re-run PHPStan. \PHPStan\dumpType($request);
\PHPStan\dumpType($request->request);
\PHPStan\dumpType($request->request->get('value')); |
I'm getting an unknown function error. I tried explicitly including the function <?php
declare (strict_types=1);
namespace PHPStan;
/**
* @param mixed $value
*/
function dumpType($value) : void
{
} |
Oops, maybe the result I am looking for is in PHPStan, not the browser:
|
These are all results I expect, as I've proposed a solution to Symfony that could be helpful if accepted: symfony/symfony#45775 |
This is not the result I expect, do you have the latest version of PHPStan and phpstan-symfony? Is the extension enabled? |
Well, that's good news! But I am afraid I do have the latest
<?php
declare(strict_types=1);
// @todo Symfony 5.4 update this file, see https://github.com/phpstan/phpstan-symfony
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
require __DIR__ . '/../config/bootstrap.php';
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
return new Application($kernel); |
I'm looking at the symfony 5 config for
While I'm running 4.4, I do use flex, I do have |
looks like |
this did not change the output of the
|
Found something potentially interesting. I see a stub for HttpFoundation bag here: https://github.com/phpstan/phpstan-symfony/blob/master/stubs/Symfony/Component/HttpFoundation/ParameterBag.stub But most other instances of ParameterBag referenced in |
This is the problem:
I'd expect this instead:
Because:
|
Not sure how it can be happening if everything's properly installed. |
Hmm. @ondrejmirtes Do you suggest I manually install phpstan-symfony? Not sure how to proceed with testing... |
@ondrejmirtes, any input on my previous comment? I am not fully competent on how stubbing works, but is it really possible to type hint a completely different object? Request defines:
That's why I was not surprised to see the dumped variable as an instance of |
Please create a small reproducing repository so I can check out the problem. |
If I find some time I will look into that and comment back here. |
well, that was easier than I thought: https://github.com/arderyp/phpstan-issue-262 |
should we open this back up @ondrejmirtes? |
I think this code doesn't execute for you: https://github.com/phpstan/phpstan-symfony/blob/1.2.x/src/Symfony/InputBagStubFilesExtension.php Can you try installing this package? https://packagist.org/packages/symfony/http-foundation |
So, unfortunately, I should note, I did not build some unique custom symfony environment to reproduce this issue in my test repo. I simply followed the symfony documentation for generating a new project and new controller using the Since this issue is affecting an out of the box installation, shouldn't we re-open it? |
Hey @ondrejmirtes, I believe part of the confusions here is stemming from the fact that you were expecting an object of type the 5.4 the 4.4 I am running Symfony 4.4, so maybe this is just the expected/limited behavior of the less-type-friendly 4.4 version of Symfony, which uses |
So upgrade your Symfony version - you'll save yourself more trouble that way :) |
I plan to this summer, but it's a major version upgrade, not a simple composer update and call it a day. Glad the newer versions play more nicely with typing and phpstan though |
Hi, I might be misunderstanding the use case of this extension, for the rule 'Provides correct return type for InputBag::get() method based on the $default parameter.' I would expect |
Good question @TomBrunner I haven't heard back from maintainers on my suggested improvements for typed getters on the |
right now I'm having to check the type on each call (mixed return), which is a lot. Not sure if this is possible, but thought I'd ask.
The text was updated successfully, but these errors were encountered: