From 2f6995dc50b51adc6c53f2104650ee12a5cf95ff Mon Sep 17 00:00:00 2001 From: Luke Kuzmish Date: Mon, 24 Feb 2025 21:06:32 -0500 Subject: [PATCH 1/3] typehints for Illuminate\Http --- src/Illuminate/Http/Client/Factory.php | 22 ++++++++++++---------- src/Illuminate/Http/Client/Pool.php | 4 ++-- src/Illuminate/Http/Client/Response.php | 7 ++++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Illuminate/Http/Client/Factory.php b/src/Illuminate/Http/Client/Factory.php index 84b8fc61a15d..aeddeea2de85 100644 --- a/src/Illuminate/Http/Client/Factory.php +++ b/src/Illuminate/Http/Client/Factory.php @@ -17,6 +17,8 @@ /** * @mixin \Illuminate\Http\Client\PendingRequest + * + * @phpstan-type RecordedRequestType array{0: \Illuminate\Http\Client\Request, 1: \Illuminate\Http\Client\Response|null} */ class Factory { @@ -62,14 +64,14 @@ class Factory /** * The recorded response array. * - * @var array + * @var list */ protected $recorded = []; /** * All created response sequences. * - * @var array + * @var list<\Illuminate\Http\Client\ResponseSequence> */ protected $responseSequences = []; @@ -170,7 +172,7 @@ public static function response($body = null, $status = 200, $headers = []) * Create a new connection exception for use during stubbing. * * @param string|null $message - * @return \GuzzleHttp\Promise\PromiseInterface + * @return \Closure(\Illuminate\Http\Client\Request): \GuzzleHttp\Promise\PromiseInterface */ public static function failedConnection($message = null) { @@ -196,7 +198,7 @@ public function sequence(array $responses = []) /** * Register a stub callable that will intercept requests and be able to return stub responses. * - * @param callable|array|null $callback + * @param callable|array|null $callback * @return $this */ public function fake($callback = null) @@ -258,7 +260,7 @@ public function fakeSequence($url = '*') * Stub the given URL using the given callback. * * @param string $url - * @param \Illuminate\Http\Client\Response|\GuzzleHttp\Promise\PromiseInterface|callable|int|string|array $callback + * @param \Illuminate\Http\Client\Response|\GuzzleHttp\Promise\PromiseInterface|callable|int|string|array|\Illuminate\Http\Client\ResponseSequence $callback * @return $this */ public function stubUrl($url, $callback) @@ -346,7 +348,7 @@ public function recordRequestResponsePair($request, $response) /** * Assert that a request / response pair was recorded matching a given truth test. * - * @param callable $callback + * @param callable|(\Closure(\Illuminate\Http\Client\Request, \Illuminate\Http\Client\Response|null): bool) $callback * @return void */ public function assertSent($callback) @@ -360,7 +362,7 @@ public function assertSent($callback) /** * Assert that the given request was sent in the given order. * - * @param array $callbacks + * @param list $callbacks * @return void */ public function assertSentInOrder($callbacks) @@ -382,7 +384,7 @@ public function assertSentInOrder($callbacks) /** * Assert that a request / response pair was not recorded matching a given truth test. * - * @param callable $callback + * @param callable|(\Closure(\Illuminate\Http\Client\Request, \Illuminate\Http\Client\Response|null): bool) $callback * @return void */ public function assertNotSent($callback) @@ -435,8 +437,8 @@ public function assertSequencesAreEmpty() /** * Get a collection of the request / response pairs matching the given truth test. * - * @param callable $callback - * @return \Illuminate\Support\Collection + * @param (\Closure(\Illuminate\Http\Client\Request, \Illuminate\Http\Client\Response|null): bool)|callable $callback + * @return \Illuminate\Support\Collection */ public function recorded($callback = null) { diff --git a/src/Illuminate/Http/Client/Pool.php b/src/Illuminate/Http/Client/Pool.php index b5f00258fbab..a540827576b2 100644 --- a/src/Illuminate/Http/Client/Pool.php +++ b/src/Illuminate/Http/Client/Pool.php @@ -26,7 +26,7 @@ class Pool /** * The pool of requests. * - * @var array + * @var array */ protected $pool = []; @@ -66,7 +66,7 @@ protected function asyncRequest() /** * Retrieve the requests in the pool. * - * @return array + * @return array */ public function getRequests() { diff --git a/src/Illuminate/Http/Client/Response.php b/src/Illuminate/Http/Client/Response.php index ac51d9c7ade8..6f2cf934ed91 100644 --- a/src/Illuminate/Http/Client/Response.php +++ b/src/Illuminate/Http/Client/Response.php @@ -236,7 +236,7 @@ public function serverError() /** * Execute the given callback if there was a server or client error. * - * @param callable $callback + * @param callable|(\Closure(\Illuminate\Http\Client\Response): mixed) $callback * @return $this */ public function onError(callable $callback) @@ -305,6 +305,7 @@ public function toException() /** * Throw an exception if a server or client error occurred. * + * @param null|(\Closure(\Illuminate\Http\Client\Response, \Throwable): mixed) $callback * @return $this * * @throws \Illuminate\Http\Client\RequestException @@ -340,7 +341,7 @@ public function throwIf($condition) /** * Throw an exception if the response status code matches the given code. * - * @param callable|int $statusCode + * @param int|(\Closure(int, \Illuminate\Http\Client\Response): bool)|callable $statusCode * @return $this * * @throws \Illuminate\Http\Client\RequestException @@ -358,7 +359,7 @@ public function throwIfStatus($statusCode) /** * Throw an exception unless the response status code matches the given code. * - * @param callable|int $statusCode + * @param int|(\Closure(int, \Illuminate\Http\Client\Response): bool)|callable $statusCode * @return $this * * @throws \Illuminate\Http\Client\RequestException From af42362e41b9e0c21616d970a67822e0db3440d4 Mon Sep 17 00:00:00 2001 From: Luke Kuzmish Date: Mon, 24 Feb 2025 21:10:43 -0500 Subject: [PATCH 2/3] remove --- src/Illuminate/Http/Client/Response.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Http/Client/Response.php b/src/Illuminate/Http/Client/Response.php index 6f2cf934ed91..c33c219616bb 100644 --- a/src/Illuminate/Http/Client/Response.php +++ b/src/Illuminate/Http/Client/Response.php @@ -305,7 +305,6 @@ public function toException() /** * Throw an exception if a server or client error occurred. * - * @param null|(\Closure(\Illuminate\Http\Client\Response, \Throwable): mixed) $callback * @return $this * * @throws \Illuminate\Http\Client\RequestException From 89ce1d08d22829deb4651920d405e8446bda88b3 Mon Sep 17 00:00:00 2001 From: Luke Kuzmish Date: Tue, 25 Feb 2025 11:04:39 -0500 Subject: [PATCH 3/3] remove phpstan-type --- src/Illuminate/Http/Client/Factory.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Http/Client/Factory.php b/src/Illuminate/Http/Client/Factory.php index aeddeea2de85..b466b1e816c8 100644 --- a/src/Illuminate/Http/Client/Factory.php +++ b/src/Illuminate/Http/Client/Factory.php @@ -17,8 +17,6 @@ /** * @mixin \Illuminate\Http\Client\PendingRequest - * - * @phpstan-type RecordedRequestType array{0: \Illuminate\Http\Client\Request, 1: \Illuminate\Http\Client\Response|null} */ class Factory { @@ -64,7 +62,7 @@ class Factory /** * The recorded response array. * - * @var list + * @var list */ protected $recorded = []; @@ -438,7 +436,7 @@ public function assertSequencesAreEmpty() * Get a collection of the request / response pairs matching the given truth test. * * @param (\Closure(\Illuminate\Http\Client\Request, \Illuminate\Http\Client\Response|null): bool)|callable $callback - * @return \Illuminate\Support\Collection + * @return \Illuminate\Support\Collection */ public function recorded($callback = null) {