-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[12.x] PendingRequest HTTP methods may also return promises #57941
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
Conversation
|
@cosmastech speaking of typehints. The basic example from the documentation fails a I hope our CI pipeline is the only one out there that crashes 😄 |
Nah, you're not. We had that issue this morning as well. I wonder if there's something with Larastan we could add to have it be more intelligent about when it returns a Promise vs when it returns a Response. |
|
Is there something missing in framework/src/Illuminate/Http/Client/PendingRequest.php Lines 936 to 947 in a78e156
- * @return \Illuminate\Http\Client\Response
+ * @return \Illuminate\Http\Client\Response|\GuzzleHttp\Promise\PromiseInterface |
Yes, and I added that in this PR: https://github.com/laravel/framework/pull/57973/files#diff-1ac9aa0ab55e04c899a86ef074016e5ebc3683e3e90101f03284305301771067R955 That said, the problem is that this PR "fixed" the return type to be technically correct, but lots of code written previously was assuming that these methods returned ONLY a Response. So the code shared above works fine, but static analysis gripes |
|
I believe there is actually a bigger problem than meets the eye here. Yes, PHPStan moans, which is incredibly annoying, especially to actually fix it in app code. However, it is completely correct. If I had any idea on a path forward for this, I would put a PR together, but I don't have a clue. My only thoughts are that perhaps async should return a modified version of the PendingRequest class, to separate the logic and capabilities? |
I agree with this: there should be two classes - one for async and the current one for sync. I had the same idea in my head, but haven't played around with trying to change this for Laravel 13. |
|
I just want to add our voices to this discussion as well. It is more or less mandatory to have static analysis in PHP in enterprise solutions to avoid costly errors. Yet this change forces us to either ignore this error, or significantly reduce the comfort of using the Http client. For example this code $response = Http::asForm()->post(...)->throw();becomes this code $response = Http::asForm()->post(...)
if ($response instanceof Response) {
$response->throw();
} else {
throw new \RuntimeException('Unexpected response type');
}Not to mention changing a return type probably should have been included in a major? |
Oh boy. Do you think Laravel cares about that? 😂 |
I'm doing my first foray into HTTP pooling, and wow, this is dope.
Because of the typehints, I wasn't aware something like this was possible: