@@ -61,14 +61,12 @@ public function read(): Response
6161 if ($ this ->hasError ($ resource )) {
6262 return $ this ->getPhpError (HttpStatus::FAILED_DEPENDENCY );
6363 }
64- $ this ->extractFromResponseHeaders ($ resource , $ headers , $ statusCode );
64+ $ this ->extractFromResponseHeaders ($ resource , $ statusCode , $ headers );
6565 return new ServerResponse (\stream_get_contents ($ resource ), $ statusCode , $ headers );
6666 } catch (\ValueError $ e ) {
6767 return $ this ->getPhpError (HttpStatus::FAILED_DEPENDENCY , $ e ->getMessage ());
6868 } catch (\Throwable $ e ) {
69- return $ this ->getPhpError (
70- $ e ->getCode () ?: HttpStatus::INTERNAL_SERVER_ERROR ,
71- $ e ->getMessage ());
69+ return $ this ->getPhpError (HttpStatus::INTERNAL_SERVER_ERROR , $ e ->getMessage ());
7270 } finally {
7371 if (\is_resource ($ resource )) {
7472 \fclose ($ resource );
@@ -137,7 +135,7 @@ protected function prepareRequestBody(): void
137135 if (0 === $ this ->encoding ) {
138136 $ this ->options ['content ' ] = $ this ->stream ->getContents ();
139137 } elseif ($ content = \json_decode ($ this ->stream ->getContents () ?: '[] ' , true )) {
140- $ this ->normalizeHeader ('Content-type ' , self ::X_WWW_FORM_URLENCODED , true );
138+ $ this ->normalizeHeader ('Content-Type ' , self ::X_WWW_FORM_URLENCODED , true );
141139 $ this ->options ['content ' ] = \http_build_query ($ content , null , '& ' , $ this ->encoding );
142140 }
143141 $ this ->stream = create_stream ($ this ->options ['content ' ]);
@@ -159,20 +157,18 @@ protected function prepareOptions(): void
159157 * Extracts the headers and status code from the response.
160158 *
161159 * @param resource $response The resource from fopen()
162- * @param array $headers Parsed response headers
163160 * @param int $statusCode Response status code
161+ * @param array $headers Parsed response headers
164162 */
165- protected function extractFromResponseHeaders ($ response , &$ headers , &$ statusCode ): void
163+ protected function extractFromResponseHeaders ($ response , &$ statusCode , &$ headers ): void
166164 {
167165 try {
168166 $ meta = \stream_get_meta_data ($ response )['wrapper_data ' ] ?? [];
169167 /* HTTP status may not always be the first header in the response headers,
170168 * for example, if the stream follows one or multiple redirects, the last
171169 * status line is what is expected here.
172170 */
173- $ statusCode = \array_filter ($ meta , function (string $ header ) {
174- return \str_starts_with ($ header , 'HTTP/ ' );
175- });
171+ $ statusCode = \array_filter ($ meta , fn (string $ header ) => \str_starts_with ($ header , 'HTTP/ ' ));
176172 $ statusCode = \array_pop ($ statusCode ) ?: 'HTTP/1.1 200 OK ' ;
177173 $ statusCode = (int )(\explode (' ' , $ statusCode )[1 ] ?? HttpStatus::OK );
178174 foreach ($ meta as $ header ) {
0 commit comments