Skip to content

Commit ed91d71

Browse files
committed
refactor(Client): improve docblock formatting and enhance readability
1 parent a74e055 commit ed91d71

File tree

1 file changed

+44
-56
lines changed

1 file changed

+44
-56
lines changed

src/Fetch/Http/Client.php

Lines changed: 44 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ class Client implements ClientInterface, LoggerAwareInterface
3737
/**
3838
* Client constructor.
3939
*
40-
* @param ClientHandlerInterface|null $handler The client handler
41-
* @param array<string, mixed> $options Default request options
42-
* @param LoggerInterface|null $logger PSR-3 logger
40+
* @param ClientHandlerInterface|null $handler The client handler
41+
* @param array<string, mixed> $options Default request options
42+
* @param LoggerInterface|null $logger PSR-3 logger
4343
*/
4444
public function __construct(
4545
?ClientHandlerInterface $handler = null,
4646
array $options = [],
4747
?LoggerInterface $logger = null,
4848
) {
4949
$this->handler = $handler ?? new ClientHandler(options: $options);
50-
$this->logger = $logger ?? new NullLogger();
50+
$this->logger = $logger ?? new NullLogger;
5151

5252
// If handler supports logging, set the logger
5353
if (method_exists($this->handler, 'setLogger')) {
@@ -58,16 +58,15 @@ public function __construct(
5858
/**
5959
* Create a new client with a base URI.
6060
*
61-
* @param string $baseUri The base URI for all requests
62-
* @param array<string, mixed> $options Default request options
63-
*
61+
* @param string $baseUri The base URI for all requests
62+
* @param array<string, mixed> $options Default request options
6463
* @return static New client instance
6564
*/
6665
public static function createWithBaseUri(string $baseUri, array $options = []): static
6766
{
6867
$handler = ClientHandler::createWithBaseUri($baseUri);
6968

70-
if ([] !== $options) {
69+
if ($options !== []) {
7170
$handler->withOptions($options);
7271
}
7372

@@ -77,7 +76,7 @@ public static function createWithBaseUri(string $baseUri, array $options = []):
7776
/**
7877
* Set a PSR-3 logger.
7978
*
80-
* @param LoggerInterface $logger PSR-3 logger
79+
* @param LoggerInterface $logger PSR-3 logger
8180
*/
8281
public function setLogger(LoggerInterface $logger): void
8382
{
@@ -102,8 +101,7 @@ public function getHandler(): ClientHandlerInterface
102101
/**
103102
* Sends a PSR-7 request and returns a PSR-7 response.
104103
*
105-
* @param RequestInterface $request PSR-7 request
106-
*
104+
* @param RequestInterface $request PSR-7 request
107105
* @return PsrResponseInterface PSR-7 response
108106
*
109107
* @throws ClientExceptionInterface If an error happens while processing the request
@@ -164,9 +162,8 @@ public function sendRequest(RequestInterface $request): PsrResponseInterface
164162
/**
165163
* Create and send an HTTP request.
166164
*
167-
* @param string|null $url The URL to fetch
168-
* @param array<string, mixed>|null $options Request options
169-
*
165+
* @param string|null $url The URL to fetch
166+
* @param array<string, mixed>|null $options Request options
170167
* @return ResponseInterface|ClientHandlerInterface Response or handler for method chaining
171168
*
172169
* @throws \RuntimeException If the request fails
@@ -225,7 +222,7 @@ public function fetch(?string $url = null, ?array $options = []): ResponseInterf
225222
try {
226223
$handler = $this->handler->withOptions($options);
227224

228-
if (null !== $body) {
225+
if ($body !== null) {
229226
$handler = $handler->withBody($body, $contentType);
230227
}
231228

@@ -251,10 +248,9 @@ public function fetch(?string $url = null, ?array $options = []): ResponseInterf
251248
/**
252249
* Make a GET request.
253250
*
254-
* @param string $url The URL to fetch
255-
* @param array<string, mixed>|null $queryParams Query parameters
256-
* @param array<string, mixed>|null $options Request options
257-
*
251+
* @param string $url The URL to fetch
252+
* @param array<string, mixed>|null $queryParams Query parameters
253+
* @param array<string, mixed>|null $options Request options
258254
* @return ResponseInterface The response
259255
*/
260256
public function get(string $url, ?array $queryParams = null, ?array $options = []): ResponseInterface
@@ -271,11 +267,10 @@ public function get(string $url, ?array $queryParams = null, ?array $options = [
271267
/**
272268
* Make a POST request.
273269
*
274-
* @param string $url The URL to fetch
275-
* @param mixed $body Request body
276-
* @param string|ContentType $contentType Content type
277-
* @param array<string, mixed>|null $options Request options
278-
*
270+
* @param string $url The URL to fetch
271+
* @param mixed $body Request body
272+
* @param string|ContentType $contentType Content type
273+
* @param array<string, mixed>|null $options Request options
279274
* @return ResponseInterface The response
280275
*/
281276
public function post(
@@ -290,11 +285,10 @@ public function post(
290285
/**
291286
* Make a PUT request.
292287
*
293-
* @param string $url The URL to fetch
294-
* @param mixed $body Request body
295-
* @param string|ContentType $contentType Content type
296-
* @param array<string, mixed>|null $options Request options
297-
*
288+
* @param string $url The URL to fetch
289+
* @param mixed $body Request body
290+
* @param string|ContentType $contentType Content type
291+
* @param array<string, mixed>|null $options Request options
298292
* @return ResponseInterface The response
299293
*/
300294
public function put(
@@ -309,11 +303,10 @@ public function put(
309303
/**
310304
* Make a PATCH request.
311305
*
312-
* @param string $url The URL to fetch
313-
* @param mixed $body Request body
314-
* @param string|ContentType $contentType Content type
315-
* @param array<string, mixed>|null $options Request options
316-
*
306+
* @param string $url The URL to fetch
307+
* @param mixed $body Request body
308+
* @param string|ContentType $contentType Content type
309+
* @param array<string, mixed>|null $options Request options
317310
* @return ResponseInterface The response
318311
*/
319312
public function patch(
@@ -328,11 +321,10 @@ public function patch(
328321
/**
329322
* Make a DELETE request.
330323
*
331-
* @param string $url The URL to fetch
332-
* @param mixed $body Request body
333-
* @param string|ContentType $contentType Content type
334-
* @param array<string, mixed>|null $options Request options
335-
*
324+
* @param string $url The URL to fetch
325+
* @param mixed $body Request body
326+
* @param string|ContentType $contentType Content type
327+
* @param array<string, mixed>|null $options Request options
336328
* @return ResponseInterface The response
337329
*/
338330
public function delete(
@@ -347,9 +339,8 @@ public function delete(
347339
/**
348340
* Make a HEAD request.
349341
*
350-
* @param string $url The URL to fetch
351-
* @param array<string, mixed>|null $options Request options
352-
*
342+
* @param string $url The URL to fetch
343+
* @param array<string, mixed>|null $options Request options
353344
* @return ResponseInterface The response
354345
*/
355346
public function head(string $url, ?array $options = []): ResponseInterface
@@ -360,9 +351,8 @@ public function head(string $url, ?array $options = []): ResponseInterface
360351
/**
361352
* Make an OPTIONS request.
362353
*
363-
* @param string $url The URL to fetch
364-
* @param array<string, mixed>|null $options Request options
365-
*
354+
* @param string $url The URL to fetch
355+
* @param array<string, mixed>|null $options Request options
366356
* @return ResponseInterface The response
367357
*/
368358
public function options(string $url, ?array $options = []): ResponseInterface
@@ -381,12 +371,11 @@ public function getHttpClient(): GuzzleClientInterface
381371
/**
382372
* Make a request with a specific HTTP method.
383373
*
384-
* @param Method $method The HTTP method
385-
* @param string $url The URL to fetch
386-
* @param mixed $body Request body
387-
* @param string|ContentType $contentType Content type
388-
* @param array<string, mixed>|null $options Request options
389-
*
374+
* @param Method $method The HTTP method
375+
* @param string $url The URL to fetch
376+
* @param mixed $body Request body
377+
* @param string|ContentType $contentType Content type
378+
* @param array<string, mixed>|null $options Request options
390379
* @return ResponseInterface The response
391380
*/
392381
protected function methodRequest(
@@ -399,7 +388,7 @@ protected function methodRequest(
399388
$options = $options ?? [];
400389
$options['method'] = $method->value;
401390

402-
if (null !== $body) {
391+
if ($body !== null) {
403392
$options['body'] = $body;
404393

405394
// Use the global normalize_content_type function
@@ -418,8 +407,7 @@ protected function methodRequest(
418407
/**
419408
* Extract options from a PSR-7 request.
420409
*
421-
* @param RequestInterface $request PSR-7 request
422-
*
410+
* @param RequestInterface $request PSR-7 request
423411
* @return array<string, mixed> Request options
424412
*/
425413
protected function extractOptionsFromRequest(RequestInterface $request): array
@@ -432,13 +420,13 @@ protected function extractOptionsFromRequest(RequestInterface $request): array
432420
$headers[$name] = implode(', ', $values);
433421
}
434422

435-
if ([] !== $headers) {
423+
if ($headers !== []) {
436424
$options['headers'] = $headers;
437425
}
438426

439427
// Add body if present
440428
$body = (string) $request->getBody();
441-
if ('' !== $body) {
429+
if ($body !== '') {
442430
$options['body'] = $body;
443431
}
444432

0 commit comments

Comments
 (0)