[10.x] Fix Http client pool return type #47530
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current docblock code presumes that any method by
PendingRequest
return itself, however, this is not the case, even for simple scenarios:Any method that represents creating an async request will return a Promise class:
get
,head
,post
,patch
,put
, anddelete
. Only methods to configure the request will return the class itself, ex:withOptions
,retry
,timeout
.When using a static analysis tool and creating a function to mock a pool request is where the problem comes. Here is an example to demonstrate it:
This pull request adds
\GuzzleHttp\Promise\Promise
to the__call
magic method fromPool
class for async requests. This will create a union, and any method called (according to the new docblock) may return any of the two classes. This may generate some uncertainty in some static analysis cases.A better way to patch this, in the static analysis view, would be creating the methods
get
,head
,post
,patch
,put
, anddelete
on the Pool class, enforcing that they will return a Promise instance and all other methods will fallback to the__call
magic method that says it returns a PendingRequest instance, which is now correct. But this will lead to some new lines of code instead of just adjusting a docblock value.