Skip to content

Commit cb88e18

Browse files
committed
refactor: code style and improve readability across multiple files
1 parent 6a335f5 commit cb88e18

File tree

7 files changed

+124
-125
lines changed

7 files changed

+124
-125
lines changed

src/Fetch/Support/DebugInfo.php

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,30 @@ class DebugInfo
4848
/**
4949
* Create a new DebugInfo instance.
5050
*
51-
* @param array<string, mixed> $requestData Request data (method, uri, headers, body)
52-
* @param ResponseInterface|null $response The HTTP response
53-
* @param array<string, float> $timings Timing information for the request
54-
* @param array<string, mixed> $connectionStats Connection statistics
55-
* @param int $memoryUsage Memory usage in bytes
51+
* @param array<string, mixed> $requestData Request data (method, uri, headers, body)
52+
* @param ResponseInterface|null $response The HTTP response
53+
* @param array<string, float> $timings Timing information for the request
54+
* @param array<string, mixed> $connectionStats Connection statistics
55+
* @param int $memoryUsage Memory usage in bytes
5656
*/
5757
public function __construct(
5858
protected array $requestData,
5959
protected ?ResponseInterface $response,
6060
protected array $timings = [],
6161
protected array $connectionStats = [],
6262
protected int $memoryUsage = 0,
63-
) {
64-
}
63+
) {}
6564

6665
/**
6766
* Create a DebugInfo instance from a request and response.
6867
*
69-
* @param string $method HTTP method
70-
* @param string $uri Request URI
71-
* @param array<string, mixed> $options Request options including headers and body
72-
* @param ResponseInterface|null $response The HTTP response
73-
* @param array<string, float> $timings Timing information
74-
* @param array<string, mixed> $connectionStats Connection statistics
75-
* @param int $memoryUsage Memory usage in bytes
68+
* @param string $method HTTP method
69+
* @param string $uri Request URI
70+
* @param array<string, mixed> $options Request options including headers and body
71+
* @param ResponseInterface|null $response The HTTP response
72+
* @param array<string, float> $timings Timing information
73+
* @param array<string, mixed> $connectionStats Connection statistics
74+
* @param int $memoryUsage Memory usage in bytes
7675
*/
7776
public static function create(
7877
string $method,
@@ -109,7 +108,7 @@ public static function getDefaultOptions(): array
109108
/**
110109
* Set default debug options.
111110
*
112-
* @param array<string, mixed> $options
111+
* @param array<string, mixed> $options
113112
*/
114113
public static function setDefaultOptions(array $options): void
115114
{
@@ -119,8 +118,7 @@ public static function setDefaultOptions(array $options): void
119118
/**
120119
* Sanitize options to redact sensitive information.
121120
*
122-
* @param array<string, mixed> $options The options to sanitize
123-
*
121+
* @param array<string, mixed> $options The options to sanitize
124122
* @return array<string, mixed> Sanitized options
125123
*/
126124
protected static function sanitizeOptions(array $options): array
@@ -143,8 +141,7 @@ protected static function sanitizeOptions(array $options): array
143141
/**
144142
* Sanitize headers to redact sensitive information.
145143
*
146-
* @param array<string, mixed> $headers The headers to sanitize
147-
*
144+
* @param array<string, mixed> $headers The headers to sanitize
148145
* @return array<string, mixed> Sanitized headers
149146
*/
150147
protected static function sanitizeHeaders(array $headers): array
@@ -213,8 +210,7 @@ public function getMemoryUsage(): int
213210
/**
214211
* Format the request information for output.
215212
*
216-
* @param array<string, mixed> $options Output options
217-
*
213+
* @param array<string, mixed> $options Output options
218214
* @return array<string, mixed>
219215
*/
220216
public function formatRequest(array $options = []): array
@@ -231,7 +227,7 @@ public function formatRequest(array $options = []): array
231227

232228
if ($options['request_body']) {
233229
$body = $this->requestData['body'] ?? null;
234-
if (null !== $body) {
230+
if ($body !== null) {
235231
$formatted['body'] = $this->formatBody($body, $options['request_body']);
236232
}
237233
}
@@ -242,13 +238,12 @@ public function formatRequest(array $options = []): array
242238
/**
243239
* Format the response information for output.
244240
*
245-
* @param array<string, mixed> $options Output options
246-
*
241+
* @param array<string, mixed> $options Output options
247242
* @return array<string, mixed>|null
248243
*/
249244
public function formatResponse(array $options = []): ?array
250245
{
251-
if (null === $this->response) {
246+
if ($this->response === null) {
252247
return null;
253248
}
254249

@@ -262,7 +257,7 @@ public function formatResponse(array $options = []): ?array
262257
$formatted['headers'] = self::sanitizeHeaders($this->response->getHeaders());
263258
}
264259

265-
if (false !== $options['response_body']) {
260+
if ($options['response_body'] !== false) {
266261
$body = (string) $this->response->getBody();
267262
$this->response->getBody()->rewind();
268263
$formatted['body'] = $this->formatBody($body, $options['response_body']);
@@ -274,8 +269,7 @@ public function formatResponse(array $options = []): ?array
274269
/**
275270
* Get the debug information as an array.
276271
*
277-
* @param array<string, mixed> $options Output options
278-
*
272+
* @param array<string, mixed> $options Output options
279273
* @return array<string, mixed>
280274
*/
281275
public function toArray(array $options = []): array
@@ -285,11 +279,11 @@ public function toArray(array $options = []): array
285279
'request' => $this->formatRequest($options),
286280
];
287281

288-
if (null !== $this->response) {
282+
if ($this->response !== null) {
289283
$result['response'] = $this->formatResponse($options);
290284
}
291285

292-
if ($options['timing'] && !empty($this->timings)) {
286+
if ($options['timing'] && ! empty($this->timings)) {
293287
$result['performance'] = $this->timings;
294288
}
295289

@@ -300,7 +294,7 @@ public function toArray(array $options = []): array
300294
];
301295
}
302296

303-
if (!empty($this->connectionStats)) {
297+
if (! empty($this->connectionStats)) {
304298
$result['connection'] = $this->connectionStats;
305299
}
306300

@@ -310,7 +304,7 @@ public function toArray(array $options = []): array
310304
/**
311305
* Get the debug information as a JSON string.
312306
*
313-
* @param array<string, mixed> $options Output options
307+
* @param array<string, mixed> $options Output options
314308
*/
315309
public function dump(array $options = []): string
316310
{
@@ -320,12 +314,12 @@ public function dump(array $options = []): string
320314
/**
321315
* Format a body for output, optionally truncating.
322316
*
323-
* @param mixed $body The body content
324-
* @param bool|int $option True for full body, int for max bytes, false to disable
317+
* @param mixed $body The body content
318+
* @param bool|int $option True for full body, int for max bytes, false to disable
325319
*/
326320
protected function formatBody(mixed $body, bool|int $option): mixed
327321
{
328-
if (false === $option) {
322+
if ($option === false) {
329323
return null;
330324
}
331325

@@ -334,7 +328,7 @@ protected function formatBody(mixed $body, bool|int $option): mixed
334328
$body = json_encode($body, JSON_PRETTY_PRINT);
335329
}
336330

337-
if (!is_string($body)) {
331+
if (! is_string($body)) {
338332
return $body;
339333
}
340334

@@ -356,7 +350,7 @@ protected function formatBytes(int $bytes): string
356350

357351
while ($bytes >= 1024 && $unitIndex < count($units) - 1) {
358352
$bytes /= 1024;
359-
++$unitIndex;
353+
$unitIndex++;
360354
}
361355

362356
return round($bytes, 2).' '.$units[$unitIndex];

src/Fetch/Support/RequestContext.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ final class RequestContext
132132
/**
133133
* Private constructor - use static factory methods.
134134
*
135-
* @param array<string, string|string[]> $headers
136-
* @param array<string, mixed> $options
137-
* @param array<string, mixed> $cacheOptions
138-
* @param array<string, mixed> $debugOptions
139-
* @param array<int> $retryableStatusCodes
140-
* @param array<class-string<\Throwable>> $retryableExceptions
135+
* @param array<string, string|string[]> $headers
136+
* @param array<string, mixed> $options
137+
* @param array<string, mixed> $cacheOptions
138+
* @param array<string, mixed> $debugOptions
139+
* @param array<int> $retryableStatusCodes
140+
* @param array<class-string<\Throwable>> $retryableExceptions
141141
*/
142142
private function __construct(
143143
string $method = 'GET',
@@ -177,15 +177,15 @@ private function __construct(
177177
*/
178178
public static function create(): self
179179
{
180-
return new self();
180+
return new self;
181181
}
182182

183183
/**
184184
* Create a context from an options array.
185185
*
186186
* This method handles the various option formats used throughout the library.
187187
*
188-
* @param array<string, mixed> $options
188+
* @param array<string, mixed> $options
189189
*/
190190
public static function fromOptions(array $options): self
191191
{
@@ -284,7 +284,7 @@ public static function fromOptions(array $options): self
284284
*
285285
* Options in $options take precedence over this context's values.
286286
*
287-
* @param array<string, mixed> $options
287+
* @param array<string, mixed> $options
288288
*/
289289
public function merge(array $options): self
290290
{
@@ -418,7 +418,7 @@ public function withRetry(int $maxRetries, int $delayMs = 100): self
418418
/**
419419
* Create a copy with custom retryable status codes.
420420
*
421-
* @param array<int> $statusCodes HTTP status codes that should trigger a retry
421+
* @param array<int> $statusCodes HTTP status codes that should trigger a retry
422422
*/
423423
public function withRetryableStatusCodes(array $statusCodes): self
424424
{
@@ -443,7 +443,7 @@ public function withRetryableStatusCodes(array $statusCodes): self
443443
/**
444444
* Create a copy with custom retryable exception types.
445445
*
446-
* @param array<class-string<\Throwable>> $exceptions Exception class names that should trigger a retry
446+
* @param array<class-string<\Throwable>> $exceptions Exception class names that should trigger a retry
447447
*/
448448
public function withRetryableExceptions(array $exceptions): self
449449
{
@@ -468,7 +468,7 @@ public function withRetryableExceptions(array $exceptions): self
468468
/**
469469
* Create a copy with caching enabled/disabled.
470470
*
471-
* @param bool|array<string, mixed> $cache
471+
* @param bool|array<string, mixed> $cache
472472
*/
473473
public function withCache(bool|array $cache = true): self
474474
{
@@ -496,7 +496,7 @@ public function withCache(bool|array $cache = true): self
496496
/**
497497
* Create a copy with debugging enabled/disabled.
498498
*
499-
* @param bool|array<string, mixed> $debug
499+
* @param bool|array<string, mixed> $debug
500500
*/
501501
public function withDebug(bool|array $debug = true): self
502502
{
@@ -524,7 +524,7 @@ public function withDebug(bool|array $debug = true): self
524524
/**
525525
* Create a copy with a header added/replaced.
526526
*
527-
* @param string|string[] $value
527+
* @param string|string[] $value
528528
*/
529529
public function withHeader(string $name, string|array $value): self
530530
{
@@ -552,7 +552,7 @@ public function withHeader(string $name, string|array $value): self
552552
/**
553553
* Create a copy with multiple headers added/replaced.
554554
*
555-
* @param array<string, string|string[]> $headers
555+
* @param array<string, string|string[]> $headers
556556
*/
557557
public function withHeaders(array $headers): self
558558
{
@@ -750,7 +750,7 @@ public function isIdempotentMethod(): bool
750750
public function shouldUseCache(): bool
751751
{
752752
return $this->cacheEnabled
753-
&& !$this->async
753+
&& ! $this->async
754754
&& $this->isSafeMethod();
755755
}
756756

@@ -774,11 +774,11 @@ public function toArray(): array
774774
];
775775

776776
// Add retry configuration if not using defaults
777-
if (self::DEFAULT_RETRYABLE_STATUS_CODES !== $this->retryableStatusCodes) {
777+
if ($this->retryableStatusCodes !== self::DEFAULT_RETRYABLE_STATUS_CODES) {
778778
$result['retry_status_codes'] = $this->retryableStatusCodes;
779779
}
780780

781-
if (self::DEFAULT_RETRYABLE_EXCEPTIONS !== $this->retryableExceptions) {
781+
if ($this->retryableExceptions !== self::DEFAULT_RETRYABLE_EXCEPTIONS) {
782782
$result['retry_exceptions'] = $this->retryableExceptions;
783783
}
784784

@@ -823,15 +823,15 @@ public function toGuzzleOptions(): array
823823
}
824824

825825
// Add headers
826-
if (!empty($this->headers)) {
826+
if (! empty($this->headers)) {
827827
$guzzleOptions['headers'] = $this->headers;
828828
}
829829

830830
// Set timeout
831831
$guzzleOptions['timeout'] = $this->timeout;
832832

833833
// Ensure connect_timeout defaults sensibly
834-
if (!isset($guzzleOptions['connect_timeout'])) {
834+
if (! isset($guzzleOptions['connect_timeout'])) {
835835
$guzzleOptions['connect_timeout'] = $this->timeout;
836836
}
837837

0 commit comments

Comments
 (0)