2323
2424class Guzzle extends AbstractBrowser
2525{
26+ /**
27+ * @var array<string, mixed>
28+ */
2629 protected array $ requestOptions = [
2730 'allow_redirects ' => false ,
2831 'headers ' => [],
@@ -159,7 +162,7 @@ protected function createResponse(Psr7Response $psr7Response): BrowserKitRespons
159162 protected function getAbsoluteUri (string $ uri ): string
160163 {
161164 $ baseUri = $ this ->client ->getConfig ('base_uri ' );
162- if (( str_contains ($ uri , ':// ' ) === 0 || str_contains ( $ uri , ' :// ' ) === false ) && !str_starts_with ($ uri , '// ' )) {
165+ if (str_contains ($ uri , ':// ' ) === false && !str_starts_with ($ uri , '// ' )) {
163166 if (str_starts_with ($ uri , '/ ' )) {
164167 $ baseUriPath = $ baseUri ->getPath ();
165168 if (!empty ($ baseUriPath ) && str_starts_with ($ uri , (string ) $ baseUriPath )) {
@@ -178,9 +181,9 @@ protected function getAbsoluteUri(string $uri): string
178181 return Uri::mergeUrls ((string )$ baseUri , $ uri );
179182 }
180183
181- protected function doRequest ($ request )
184+ protected function doRequest (object $ request ): BrowserKitResponse
182185 {
183- /** @var $request BrowserKitRequest **/
186+ /** @var BrowserKitRequest $request **/
184187 $ guzzleRequest = new Psr7Request (
185188 $ request ->getMethod (),
186189 $ request ->getUri (),
@@ -190,12 +193,12 @@ protected function doRequest($request)
190193 $ options = $ this ->requestOptions ;
191194 $ options ['cookies ' ] = $ this ->extractCookies ($ guzzleRequest ->getUri ()->getHost ());
192195 $ multipartData = $ this ->extractMultipartFormData ($ request );
193- if (! empty ( $ multipartData) ) {
196+ if ($ multipartData !== [] ) {
194197 $ options ['multipart ' ] = $ multipartData ;
195198 }
196199
197200 $ formData = $ this ->extractFormData ($ request );
198- if (empty ( $ multipartData) && $ formData ) {
201+ if ($ multipartData === [] && $ formData ) {
199202 $ options ['form_params ' ] = $ formData ;
200203 }
201204
@@ -213,6 +216,7 @@ protected function doRequest($request)
213216 $ response = $ requestException ->getResponse ();
214217 }
215218
219+ // @phpstan-ignore-next-line
216220 return $ this ->createResponse ($ response );
217221 }
218222
@@ -237,6 +241,9 @@ protected function extractHeaders(BrowserKitRequest $browserKitRequest): array
237241 return $ headers ;
238242 }
239243
244+ /**
245+ * @return array<int, mixed>|null
246+ */
240247 protected function extractFormData (BrowserKitRequest $ browserKitRequest ): ?array
241248 {
242249 if (!in_array (strtoupper ($ browserKitRequest ->getMethod ()), ['POST ' , 'PUT ' , 'PATCH ' , 'DELETE ' ])) {
@@ -257,7 +264,10 @@ protected function extractFormData(BrowserKitRequest $browserKitRequest): ?array
257264 return $ browserKitRequest ->getParameters ();
258265 }
259266
260- protected function extractMultipartFormData (BrowserKitRequest $ browserKitRequest )
267+ /**
268+ * @return array<string, mixed>
269+ */
270+ protected function extractMultipartFormData (BrowserKitRequest $ browserKitRequest ): array
261271 {
262272 if (!in_array (strtoupper ($ browserKitRequest ->getMethod ()), ['POST ' , 'PUT ' , 'PATCH ' ])) {
263273 return [];
@@ -275,7 +285,10 @@ protected function extractMultipartFormData(BrowserKitRequest $browserKitRequest
275285 return $ parts ;
276286 }
277287
278- protected function formatMultipart ($ parts , string $ key , $ value )
288+ /**
289+ * @return array<string, mixed>
290+ */
291+ protected function formatMultipart (mixed $ parts , string $ key , mixed $ value ): array
279292 {
280293 if (is_array ($ value )) {
281294 foreach ($ value as $ subKey => $ subValue ) {
@@ -289,7 +302,11 @@ protected function formatMultipart($parts, string $key, $value)
289302 return $ parts ;
290303 }
291304
292- protected function mapFiles ($ requestFiles , ?string $ arrayName = '' ): array
305+ /**
306+ * @param array<int, mixed> $requestFiles
307+ * @return array<int, mixed>
308+ */
309+ protected function mapFiles (array $ requestFiles , ?string $ arrayName = '' ): array
293310 {
294311 $ files = [];
295312 foreach ($ requestFiles as $ name => $ info ) {
@@ -329,7 +346,7 @@ protected function mapFiles($requestFiles, ?string $arrayName = ''): array
329346 return $ files ;
330347 }
331348
332- protected function extractCookies ($ host ): GuzzleCookieJar
349+ protected function extractCookies (string $ host ): GuzzleCookieJar
333350 {
334351 $ jar = [];
335352 $ cookies = $ this ->getCookieJar ()->all ();
@@ -345,7 +362,7 @@ protected function extractCookies($host): GuzzleCookieJar
345362 return new GuzzleCookieJar (false , $ jar );
346363 }
347364
348- public static function createHandler ($ handler ): GuzzleHandlerStack
365+ public static function createHandler (mixed $ handler ): GuzzleHandlerStack
349366 {
350367 if ($ handler instanceof GuzzleHandlerStack) {
351368 return $ handler ;
@@ -370,6 +387,9 @@ public static function createHandler($handler): GuzzleHandlerStack
370387 return GuzzleHandlerStack::create ();
371388 }
372389
390+ /**
391+ * @param array<string, mixed> $config
392+ */
373393 public function setAwsAuth (array $ config ): void
374394 {
375395 $ this ->awsCredentials = new AwsCredentials ($ config ['key ' ], $ config ['secret ' ]);
0 commit comments