23
23
24
24
class Guzzle extends AbstractBrowser
25
25
{
26
+ /**
27
+ * @var array<string, mixed>
28
+ */
26
29
protected array $ requestOptions = [
27
30
'allow_redirects ' => false ,
28
31
'headers ' => [],
@@ -159,7 +162,7 @@ protected function createResponse(Psr7Response $psr7Response): BrowserKitRespons
159
162
protected function getAbsoluteUri (string $ uri ): string
160
163
{
161
164
$ 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 , '// ' )) {
163
166
if (str_starts_with ($ uri , '/ ' )) {
164
167
$ baseUriPath = $ baseUri ->getPath ();
165
168
if (!empty ($ baseUriPath ) && str_starts_with ($ uri , (string ) $ baseUriPath )) {
@@ -178,9 +181,9 @@ protected function getAbsoluteUri(string $uri): string
178
181
return Uri::mergeUrls ((string )$ baseUri , $ uri );
179
182
}
180
183
181
- protected function doRequest ($ request )
184
+ protected function doRequest (object $ request ): BrowserKitResponse
182
185
{
183
- /** @var $request BrowserKitRequest **/
186
+ /** @var BrowserKitRequest $request **/
184
187
$ guzzleRequest = new Psr7Request (
185
188
$ request ->getMethod (),
186
189
$ request ->getUri (),
@@ -190,12 +193,12 @@ protected function doRequest($request)
190
193
$ options = $ this ->requestOptions ;
191
194
$ options ['cookies ' ] = $ this ->extractCookies ($ guzzleRequest ->getUri ()->getHost ());
192
195
$ multipartData = $ this ->extractMultipartFormData ($ request );
193
- if (! empty ( $ multipartData) ) {
196
+ if ($ multipartData !== [] ) {
194
197
$ options ['multipart ' ] = $ multipartData ;
195
198
}
196
199
197
200
$ formData = $ this ->extractFormData ($ request );
198
- if (empty ( $ multipartData) && $ formData ) {
201
+ if ($ multipartData === [] && $ formData ) {
199
202
$ options ['form_params ' ] = $ formData ;
200
203
}
201
204
@@ -213,6 +216,7 @@ protected function doRequest($request)
213
216
$ response = $ requestException ->getResponse ();
214
217
}
215
218
219
+ // @phpstan-ignore-next-line
216
220
return $ this ->createResponse ($ response );
217
221
}
218
222
@@ -237,6 +241,9 @@ protected function extractHeaders(BrowserKitRequest $browserKitRequest): array
237
241
return $ headers ;
238
242
}
239
243
244
+ /**
245
+ * @return array<int, mixed>|null
246
+ */
240
247
protected function extractFormData (BrowserKitRequest $ browserKitRequest ): ?array
241
248
{
242
249
if (!in_array (strtoupper ($ browserKitRequest ->getMethod ()), ['POST ' , 'PUT ' , 'PATCH ' , 'DELETE ' ])) {
@@ -257,7 +264,10 @@ protected function extractFormData(BrowserKitRequest $browserKitRequest): ?array
257
264
return $ browserKitRequest ->getParameters ();
258
265
}
259
266
260
- protected function extractMultipartFormData (BrowserKitRequest $ browserKitRequest )
267
+ /**
268
+ * @return array<string, mixed>
269
+ */
270
+ protected function extractMultipartFormData (BrowserKitRequest $ browserKitRequest ): array
261
271
{
262
272
if (!in_array (strtoupper ($ browserKitRequest ->getMethod ()), ['POST ' , 'PUT ' , 'PATCH ' ])) {
263
273
return [];
@@ -275,7 +285,10 @@ protected function extractMultipartFormData(BrowserKitRequest $browserKitRequest
275
285
return $ parts ;
276
286
}
277
287
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
279
292
{
280
293
if (is_array ($ value )) {
281
294
foreach ($ value as $ subKey => $ subValue ) {
@@ -289,7 +302,11 @@ protected function formatMultipart($parts, string $key, $value)
289
302
return $ parts ;
290
303
}
291
304
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
293
310
{
294
311
$ files = [];
295
312
foreach ($ requestFiles as $ name => $ info ) {
@@ -329,7 +346,7 @@ protected function mapFiles($requestFiles, ?string $arrayName = ''): array
329
346
return $ files ;
330
347
}
331
348
332
- protected function extractCookies ($ host ): GuzzleCookieJar
349
+ protected function extractCookies (string $ host ): GuzzleCookieJar
333
350
{
334
351
$ jar = [];
335
352
$ cookies = $ this ->getCookieJar ()->all ();
@@ -345,7 +362,7 @@ protected function extractCookies($host): GuzzleCookieJar
345
362
return new GuzzleCookieJar (false , $ jar );
346
363
}
347
364
348
- public static function createHandler ($ handler ): GuzzleHandlerStack
365
+ public static function createHandler (mixed $ handler ): GuzzleHandlerStack
349
366
{
350
367
if ($ handler instanceof GuzzleHandlerStack) {
351
368
return $ handler ;
@@ -370,6 +387,9 @@ public static function createHandler($handler): GuzzleHandlerStack
370
387
return GuzzleHandlerStack::create ();
371
388
}
372
389
390
+ /**
391
+ * @param array<string, mixed> $config
392
+ */
373
393
public function setAwsAuth (array $ config ): void
374
394
{
375
395
$ this ->awsCredentials = new AwsCredentials ($ config ['key ' ], $ config ['secret ' ]);
0 commit comments